[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Entries Cache Performance & fast svn_time_from_cstring code

From: Brandon Ehle <azverkan_at_yahoo.com>
Date: 2002-11-27 00:12:59 CET

>
>
>>>You may like to try the following patch. It should parse the file
>>>only once when there is a write lock.
>>>
>>>
>>I'm seeing about a 14% speed boost with this patch.
>>
>>
>
>Is that elapsed time or CPU or both? Which operation?
>
>I don't see as much as that, I get about 4-5% CPU savings for an
>update which changes 500 out of 1000 files spread over 340
>directories.
>
>
This is elapsed time minus startup time (before the app gets to main).

I get about a 14% boost with your patch and additional 5% boost with
using this version of svn_time_from_cstring(). Its not pretty, but its
pretty fast. With these two changes svn_time_from_cstring() falls
completely off the profiler and the next bigger hitter is write_entry().

=============================================

unsigned long fast_strtoul10(const char *nptr, char **endptr)
{
  register const char *s=nptr;
  register int c;
  register int found;
  register unsigned long val=0;
  if(!nptr) {
    *endptr=(char*)nptr;
    return 0;
  }
  while(1) {
    c=*s++;
    c -= '0';
    if (c<0 || c>9)
      break;
    found = 1;
    val *= 10;
    val += c;
  }
  if(endptr) *endptr=(char*)(found?s-1:nptr);
  return val;
}

svn_error_t *
svn_time_from_cstring(apr_time_t *when, const char *data, apr_pool_t *pool)
{
  apr_time_exp_t exploded_time;
  apr_status_t apr_err;
  char wday[4], month[4];
  int failed=0;
  char *c=NULL;

  exploded_time.tm_year=fast_strtoul10(data, &c);
  failed+=*c!='-';
  exploded_time.tm_mon=fast_strtoul10(c+1, &c);
  failed+=*c!='-';
  exploded_time.tm_mday=fast_strtoul10(c+1, &c);
  failed+=*c!='T';
  exploded_time.tm_hour=fast_strtoul10(c+1, &c);
  failed+=*c!=':';
  exploded_time.tm_min=fast_strtoul10(c+1, &c);
  failed+=*c!=':';
  exploded_time.tm_sec=fast_strtoul10(c+1, &c);
  failed+=*c!='.';
  exploded_time.tm_usec=fast_strtoul10(c+1, &c);
  failed+=*c!='Z';

// printf("%s -> %d %d %d %d %d %d %d\n", data, exploded_time.tm_year,
exploded_time.tm_mon, exploded_time.tm_mday, exploded_time.tm_hour,
exploded_time.tm_min, exploded_time.tm_sec, exploded_time.tm_usec);

  /* First try the new timestamp format. */
  if (!failed)
    {
      exploded_time.tm_year -= 1900;
      exploded_time.tm_mon -= 1;
      exploded_time.tm_wday = 0;
      exploded_time.tm_yday = 0;
      exploded_time.tm_isdst = 0;
      exploded_time.tm_gmtoff = 0;
     
      apr_err = apr_implode_gmt (when, &exploded_time);
      if(apr_err != APR_SUCCESS)
        {
          return svn_error_createf (SVN_ERR_BAD_DATE, apr_err, NULL,
                                    "Date conversion failed.");
        }
     
      return SVN_NO_ERROR;
    }
  /* Then try the compatibility option. */
  else if (sscanf (data,
                   old_timestamp_format,
                   wday,
                   &exploded_time.tm_mday,
                   month,
                   &exploded_time.tm_year,
                   &exploded_time.tm_hour,
                   &exploded_time.tm_min,
                   &exploded_time.tm_sec,
                   &exploded_time.tm_usec,
                   &exploded_time.tm_yday,
                   &exploded_time.tm_isdst,
                   &exploded_time.tm_gmtoff) == 11)
    {
      exploded_time.tm_year -= 1900;
      exploded_time.tm_yday -= 1;
      /* Using hard coded limits for the arrays - they are going away
         soon in any case. */
      exploded_time.tm_wday = find_matching_string (wday, 7,
apr_day_snames);
      exploded_time.tm_mon = find_matching_string (month, 12,
apr_month_snames);

      apr_err = apr_implode_gmt (when, &exploded_time);
      if(apr_err != APR_SUCCESS)
        {
          return svn_error_createf (SVN_ERR_BAD_DATE, apr_err, NULL,
                                    "Date conversion failed.");
        }

      return SVN_NO_ERROR;
    }
  /* Timestamp is something we do not recognize. */
  else
    {
      return svn_error_createf(SVN_ERR_BAD_DATE, 0, NULL,
                               "Date parsing failed.");
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Nov 27 00:11:53 2002

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.