Repository navigation
Stop /historical/json/ from querying once per result - #125
Open
konradvoelkel wants to merge 1 commit into
Open
konradvoelkel wants to merge 1 commit into
konradvoelkel wants to merge 1 commit into
Conversation
gethistoricaldata() holds on to Result querysets and reads res.benchmark
when it assembles the response, so each result costs an extra query. With
200 legacy benchmarks over 12 revisions the endpoint issued 617 queries;
with select_related('benchmark') it issues 17, and the response is byte for
byte identical (same sha256, 14644 bytes).
The test pins the invariant rather than a number: the query count must not
grow when the number of benchmarks does. Before the change it fails with
144 queries for 25 benchmarks against 44 for 5.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch has not been deployed
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.
gethistoricaldata()assembles its response fromResultquerysets it keeps around, readingres.benchmarkas it goes. Withoutselect_related('benchmark')that costs one extra query per result.Measured by rendering
/historical/json/underCaptureQueriesContextwith one executable, 12 revisions and a growing number of legacy benchmarks:The response body is byte for byte identical before and after (same sha256, 14644 bytes at 200 benchmarks);
select_relatedonly changes how the rows are fetched.The test
TestHistoricalDataQueriespins the invariant rather than a query count, so it will not need adjusting whenever an unrelated query is added or dropped: the number of queries must not grow when the number of benchmarks does. Before this change it fails withNotes for a reviewer
HISTORICAL_CACHE_SECONDS), so this is about cache misses — the first request after a deploy or an upload, which is also the slow one.Result.objects.filter(...)calls inviews.pyeither usevalues_list()or already haveselect_related./historical/json/raisesAttributeErroron any site that does not defineDEF_BASELINES/DEF_EXECUTABLES, because those are read without thehasattrguard the rest ofviews.pyuses, andcodespeed/settings.pyonly ships the long-renamed singularDEF_BASELINE. Happy to open an issue if it is not already known.🤖 Generated with Claude Code