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

optimization: caching resultspace environments #185

Merged
merged 2 commits into from
Apr 7, 2015

Conversation

jbohren
Copy link
Contributor

@jbohren jbohren commented Apr 3, 2015

This can save something like 0.2s when starting up if the same resultspace gets loaded twice.

@wjwwood
Copy link
Member

wjwwood commented Apr 6, 2015

Is there a reason and/or a way to get the uncached version? This is the pattern I usually follow:

_foo_cache = {}

def get_foo_cached(arg):
    global _foo_cache
    if arg not in _foo_cache:
        _foo_cache[arg] = get_foo(arg)
    return _foo_cache[arg]


def get_foo(arg):
    # ... Some implementation
    return foo

# ... Somewhere else:

foo = get_foo_cached(arg)

This way it is obvious from the calling code that you are getting a cached value, and it is possible to get an uncached result if desired. What's your opinion?

@jbohren
Copy link
Contributor Author

jbohren commented Apr 6, 2015

I don't really care either way. The only time you'd want to reload it is if
it changes while a single instance of catkin is running.

On Mon, Apr 6, 2015, 18:50 William Woodall notifications@github.com wrote:

Is there a reason and/or a way to get the uncached version? This is the
pattern I usually follow:

_foo_cache = {}
def get_foo_cached(arg):
global _foo_cache
if arg not in _foo_cache:
_foo_cache[arg] = get_foo(arg)
return _foo_cache[arg]

def get_foo(arg):
... Some implementation
return foo

... Somewhere else:

foo = get_foo_cached(arg)

This way it is obvious from the calling code that you are getting a cached
value, and it is possible to get an uncached result if desired. What's your
opinion?

Reply to this email directly or view it on GitHub
#185 (comment).

@jbohren
Copy link
Contributor Author

jbohren commented Apr 7, 2015

@wjwwood Take a look at 866e111, I just added an option to enable/disable caching.

@wjwwood
Copy link
Member

wjwwood commented Apr 7, 2015

lgtm, thanks.

wjwwood added a commit that referenced this pull request Apr 7, 2015
optimization: caching resultspace environments
@wjwwood wjwwood merged commit d1d2bea into catkin:master Apr 7, 2015
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