Skip to content

Speed up caching #4383

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Speed up caching #4383

wants to merge 6 commits into from

Conversation

connorjward
Copy link
Contributor

@connorjward connorjward commented Jun 20, 2025

This is a bit of a refactor of parallel_cache to try and address the performance issues reported in #3983.

Fixes #3983

TODOs

  • Verify that this is parallel safe (esp. check with G-ADOPT)

The main changes are:

  • API changes comm_getter to get_comm and cache_factory to make_cache.
  • Do not use as_hexdigest every time we do a cache lookup. I think this was the main cause of the slowdown.
  • Identify caches by a local ID attribute not type(make_cache()).__class__.__name__ which was unsafe and slow (?).

Using the example from #3983 the performance improvement takes us (with a hot cache) from 31s to 14s, so I must be doing something right.

@connorjward connorjward force-pushed the connorjward/cache-fixes branch from de050ee to 3951383 Compare June 25, 2025 10:05
@connorjward connorjward requested a review from ksagiyam June 25, 2025 10:06
@connorjward connorjward marked this pull request as ready for review June 25, 2025 10:06
Copy link
Contributor

@ksagiyam ksagiyam left a comment

Choose a reason for hiding this comment

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

Otherwise, looks good to me.

Comment on lines +261 to +262
def __eq__(self, other) -> bool:
return type(other) is type(self) and hash(other) == hash(self)
Copy link
Contributor

Choose a reason for hiding this comment

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

There could be hash collisions, so we should just compare item by item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. I was lazy and didn't want to write them all out for __hash__ and __eq__.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Caching implementation is slow
2 participants