Changes between Initial Version and Version 2 of Ticket #34681


Ignore:
Timestamp:
Jun 27, 2023, 2:08:58 AM (15 months ago)
Author:
Adam Johnson
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #34681

    • Property Owner changed from nobody to Adam Johnson
  • Ticket #34681 – Description

    initial v2  
    1 The cache functino memcache_key_warnings() iterates the key character-by-character, a slow operation in Python because it has to create and destroy many individual `str` objects. Instead, we can search the string with a regular expression for a 6x speedup.
     1The cache functino memcache_key_warnings() iterates the key character-by-character, a slow operation in Python because it has to create and destroy many individual `str` objects. Instead, we can search the string with a regular expression for a ~3x speedup on a reasonably sized error-free cache key.
    22
    33IPython session comparing old and new approaches:
     
    2323   ...:             break
    2424   ...:
    25    ...: memcached_error_chars_re = re.compile(r"[\x00-\x32\x127]")
     25   ...: memcached_error_chars_re = re.compile(r"[\x00-\x20\x7f]")
    2626   ...:
    2727   ...:
     
    3232   ...:             "(longer than %s)" % (key, MEMCACHE_MAX_KEY_LENGTH)
    3333   ...:         )
    34    ...:     if memcached_error_chars_re.match(key):
     34   ...:     if memcached_error_chars_re.search(key):
    3535   ...:         yield (
    3636   ...:             "Cache key contains characters that will cause errors if "
    3737   ...:             "used with memcached: %r" % key
    3838   ...:         )
    39    ...:
    4039
    4140In [2]: %timeit list(old('acme-bookstore-user-1234567-book-78910391'))
    42 1.35 µs ± 1.09 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
     411.35 µs ± 1.05 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
    4342
    4443In [3]: %timeit list(new('acme-bookstore-user-1234567-book-78910391'))
    45 212 ns ± 1.42 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
     44475 ns ± 1.37 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
    4645
    4746In [4]: %timeit list(old('homepage\n'))
    48 545 ns ± 1.17 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
     47546 ns ± 2.88 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
    4948
    5049In [5]: %timeit list(new('homepage\n'))
    51 209 ns ± 1.03 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
     50413 ns ± 1.35 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)
    5251}}}
Back to Top