Skip to content

Specify cache key via protocol #80

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

Merged
merged 2 commits into from
Oct 30, 2023

Conversation

PhilReinhold
Copy link
Collaborator

Using id to cache objects for CachedExpressionConvertible is a bug, because the id may be reused between objects resulting in incorrect retrieval if the objects have a lifetime shorter than that of the program.

Comment on lines +477 to +478
if item._oqpy_cache_key is None:
item._oqpy_cache_key = uuid.uuid1()
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming that uuid are unique, this essentially means that we are turning cache off for those elements where _oqpy_cache_key is not provided. If that is the case, we can just do away with using uuid and return item._to_oqpy_expression().to_ast(program) on every invocation where _oqpy_cache_key is absent.

This will also avoid (however unlikely) uuid hash collisions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm I don't think that's true. If the same object is used multiple times, (which was the original motivation with the cache, since we used id as a key), then the _to_oqpy_expression should only get called once.

Not worried about uuid collisions :) https://jhall.io/archive/2021/05/19/what-are-the-odds/

Copy link
Contributor

@braised-babbage braised-babbage left a comment

Choose a reason for hiding this comment

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

Oof, yes good catch.

@PhilReinhold PhilReinhold merged commit 43d4456 into main Oct 30, 2023
@jcjaskula-aws jcjaskula-aws deleted the pcrein/specify-cache-key-via-protocol branch June 17, 2024 15:56
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.

3 participants