-
Notifications
You must be signed in to change notification settings - Fork 1k
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 computation of JSON nodes to improve performance #995
Open
hudson-ai
wants to merge
14
commits into
guidance-ai:main
Choose a base branch
from
hudson-ai:json_caching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f132dfe
JSON: replace all mappings and sequences with hashable/immutable coun…
hudson-ai 3484fe8
cache definition building
hudson-ai 55d39e4
Merge branch 'main' into json_caching
hudson-ai a56c2ef
Merge branch 'main' into json_caching
hudson-ai d3c7014
Merge branch 'main' into json_caching
hudson-ai 1a37e04
typing: tuples should be variadic
hudson-ai 49aa500
move allof, oneof, const handling to their own functions
hudson-ai 5244b3b
clear caches in tests
hudson-ai de55f4f
Merge branch 'main' into json_caching
hudson-ai c5a57ae
Merge branch 'main' into json_caching
hudson-ai d6e8c72
Merge branch 'main' into json_caching
hudson-ai 6a96068
Merge branch 'main' into json_caching
hudson-ai 95e05c5
Merge branch 'main' into json_caching
hudson-ai 84bd1e0
Merge branch 'main' into json_caching
hudson-ai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
|
||
install_requires = [ | ||
"diskcache", | ||
"frozendict", | ||
"numpy", | ||
"ordered_set", | ||
"platformdirs", | ||
|
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If adding cache here gives a speed up, will this result in every generated integer being the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll certainly double check before marking this as non-WIP, but I believe it's just caching the return value of this function, which is a
GrammarFunction
, not the actual string value. In other words, I believe the answer to your question is noThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related question, assuming that the return value is OK: does this get cross-referenced properly when the grammar is generated? Looking at some of the serialisation code, I expect that it does, but would be good to make sure that it doesn't get expanded inline multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache=True
will ensure that subsequent calls with the same arguments will always return the exact same object (i.e.id(o1) == id(o2)
).The serialization code maintains its own cache for handling "pointers" (just integer indices) to objects in the serialized grammar, as you can see here.
GrammarFunction
s are hashable and just hash to theid
of the object, so this code should correctly respect the object caching we do in the decorator.