Menu

#179 soapcpp2: is_eq_nons() optimizations (28% improvement on win)

Patch
closed
5
2020-03-13
2020-03-07
No

is_eq_nons() optimizations reducing the runtime on a Windows box (skylake) from 5.72s to 4.11s when chewing on VirtualBox's soap API.

With [#178] applied at took soapcpp2 for a spin in Visual Studio's analyzer and it pointed to is_eq_nons() as a hot spot, esp. the strlen of the second string (t) got lots of hits. Changes:

  • Seeing that the 2nd argument always was a Symbol, it it now includes a length I've eliminated that operation.
  • When SOAP_OLD_DIRECTIVE_NAME_MATCHING isn't defined, we can just drop the other strlen(s) and use strcmp. When SOAP_OLD_DIRECTIVE_NAME_MATCHING is defined, memcmp should yield a better result than strncmp as the it doesn't need to keep a lookout for the null terminator.
  • The strstr was also pointed out by Visual Studio, so I've partially replaced it with a memchr since we've got the string length already.
  • The 'ch' usage in the two loops at the begining is just to spell it out to the compiler that it shouldn't read the memory twice when skippin underscores and colons.
  • The patch include a compile fix for C99 compilers (LONG64 k) as I using the 2010 compiler when testing this.a

Cheers,
knut.

1 Attachments

Related

Patches: #178

Discussion

  • Robert van Engelen

    I'd just change the is_eq_ns() to the following to speed this up a bit:

    int
    is_eq_nons(const char *s, const char *t)
    {
    #ifdef SOAP_OLD_DIRECTIVE_NAME_MATCHING
      size_t n, m;
    #endif
      const char *r;
      while (*s == '_' || *s == ':')
        s++;
      while (*t == '_' || *t == ':')
        t++;
      if (!*s || !*t)
        return 0;
      r = strstr(t, "__");
      if (r)
        t = r + 2;
    #ifdef SOAP_OLD_DIRECTIVE_NAME_MATCHING
      n = strlen(s) - 1;
      m = strlen(t) - 1;
      while (n > 0 && s[n] == '_')
        n--;
      while (m > 0 && t[m] == '_')
        m--;
      if (n != m)
        return 0;
      return !strncmp(s, t, n + 1);
    #else
      return !strcmp(s, t);
    #endif
    }
    
     
  • Robert van Engelen

    • status: open --> pending
     
  • Robert van Engelen

    • status: pending --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB