Brett Cannon added the comment:

re.compile() calls _compile() which has the lru_cache decorator so it will 
trigger it. But you make a good point, Antoine, that it's the hit overhead here 
that we care about as long as misses don't get worse as the calculation of is 
to be cached should overwhelm anything the LRU does.

With a simplified _make_key() I can get regex_compile w/ cache clearing turned 
off to be 1.28x faster by making it be::

    if not typed:
        if len(kwds) == 0:
            return args, ()
        else:
            return args, tuple(sorted(kwds.items()))
    else:
        if len(kwds) == 0:
            return (tuple((type(arg), arg) for arg in args), ())
        else:
            return (tuple((type(arg), arg) for arg in args),
                    tuple((type(v), (k, v)) for k, v in kwds.items()))

That might not be the fastest way to handle keyword arguments (since 
regex_compile w/ caching and leaving out the len(kwds) trick out becomes 1.13x 
slower), but at least for the common case of positional arguments it seems 
faster and the code is easier to read IMO.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16389>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to