Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache 'redbaron_classname_to_baron_type', giving ~30% performance boost on 'find_all' heavy code. #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gasparka
Copy link

Low hanging fruit!

@@ -19,7 +19,8 @@
def baron_type_to_redbaron_classname(baron_type):
return "".join(map(lambda x: x.capitalize(), baron_type.split("_"))) + "Node"


from functools import lru_cache

Choose a reason for hiding this comment

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

Imports should be top level

@@ -19,7 +19,8 @@
def baron_type_to_redbaron_classname(baron_type):
return "".join(map(lambda x: x.capitalize(), baron_type.split("_"))) + "Node"


from functools import lru_cache

Choose a reason for hiding this comment

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

functools.lru_cache is python3 only and will not work in python2. It might be easy to write a cache decorator with no max size:

def memoize(function):
    memo = {}

    @wraps(function)
    def wrapper(*args):
        if args in memo:
            return memo[args]
        else:
            rv = function(*args)
            memo[args] = rv
            return rv
    return wrapper

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