FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add a (somewhat simple-minded) cache to the Python 2 version too. by gvanrossum · Pull Request #291 · python/typing · GitHub

Repository navigation

Add a (somewhat simple-minded) cache to the Python 2 version too. - #291

Merged
gvanrossum merged 2 commits into
masterfrom
py2cache
Oct 5, 2016
Merged

gvanrossum merged 2 commits into
masterfrom
py2cache

Conversation

gvanrossum commented Oct 4, 2016 •
edited
Loading

Copy link
Copy Markdown
Member

Fixes #290. Timing example:

Without cache:

$ python2 -m timeit -s 'import typing' 'typing.List[typing.List[str]]'
10000 loops, best of 3: 542 usec per loop

With cache:

$ python2 -m timeit -s 'import typing' 'typing.List[typing.List[str]]'
1000000 loops, best of 3: 1.65 usec per loop

That's about a 300x speedup!

Copy link
Copy Markdown
Member Author

@ilevkivskyi Do you see anything wrong with this?

Comment thread python2/typing.py Outdated
AnyStr = TypeVar('AnyStr', bytes, unicode)


def _tp_cache(func, maxsize=128):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

A small comment: With this definition we could not later write:

@_tp_cache(maxsize=200)
def __getitem__(self, parameters):
    ...

This causes an error (function takes at least 1 argument...). I would propose to either make maxsize a constant MAXSIZE or use the decorator with args pattern here.

Except for this small comment, everything LGTM.

Copy link
Copy Markdown
Member Author

It's not tunable in the Python 3 version either, so I just made it a local.

gvanrossum merged commit 2dbf3fd into master Oct 5, 2016
gvanrossum deleted the py2cache branch October 14, 2016 21:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL