perf(steps): cache steps_for_frame DB calls in find_frame - #44
Open
praneshnikhar wants to merge 2 commits into
Open
perf(steps): cache steps_for_frame DB calls in find_frame#44praneshnikhar wants to merge 2 commits into
praneshnikhar wants to merge 2 commits into
Conversation
find_frame calls steps_for_frame for every frame in a document, each of which queries the DB. On a document with N frames, this is N redundant DB round-trips per step expansion. Add a simple dict cache keyed by (evidence frame_ids, max_steps) so identical frames hit the cache instead of re-querying the DB. All existing tests pass; behavior is identical, just faster.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
find_frame calls steps_for_frame for every frame in a document, each of which queries the DB and loads element trees. With N frames, that's N redundant round-trips.
This PR adds a simple dict cache keyed on (evidence frame_ids, max_steps). Since find_frame passes the same include_text=False and max_steps for all frames, identical frames hit the cache instead of re-querying the DB.
No behavior change — all existing tests pass. The cache is scoped to a single find_frame call so there are no stale-data concerns.