LocalStore: Reduce number of SQLite calls - #574
Open
edolstra wants to merge 4 commits into
Open
Conversation
Instead of checking isValidPath_() and then doing either an insert or an update, registerValidPaths() now unconditionally executes a single "insert ... on conflict (path) do update ... returning id" statement. The update clause only touches the columns that updatePathInfo() used to update (hash, narSize, ultimate, sigs, ca), so registrationTime, deriver and provenance are preserved for already-valid paths. To distinguish an insert from an update (in which case the derivation outputs are already registered and we can return early), we clear the last-inserted rowid before executing the statement and compare it against the returned id afterwards. Also, registerValidPaths() now reuses the path ids returned by addValidPath() instead of looking them up again with queryValidPathId(). This reduces the number of SQLite calls instantiating my NixOS config on an empty store from 379086 to 352955. Assisted-by: Claude Fable 5 <noreply@anthropic.com>
queryValidPathId() and isValidPath_() used the QueryPathInfo statement, which returns a lot of columns (hash, deriver, sigs, ca, ...) that they don't need. Add a QueryValidPathId statement that only returns the id. Assisted-by: Claude Fable 5 <noreply@anthropic.com>
While adding references, we do a huge number of valid path id lookups that most of the time are for paths already in pathInfoCache. However, ValidPathInfo doesn't contain the SQLite id. So local-store.cc now uses LocalStorePathInfo, a subclass of ValidPathInfo that adds an id field (similar to how BinaryCacheStore uses NarInfo), for the path infos it creates and caches. queryValidPathId() then returns the id from the cache if available, and only falls back to a database query on a cache miss. This further reduces the number of SQLite calls on my NixOS config from 352955 to 225397. Assisted-by: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
cole-h
approved these changes
Jul 22, 2026
edolstra
force-pushed
the
fewer-sqlite-calls
branch
from
July 23, 2026 11:30
04fe233 to
b800e65
Compare
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.
Motivation
Use SQLite upserts and cache path IDs to reduce the number of SQLite calls.
This reduces the number of SQLite calls instantiating my NixOS config on an empty store from 379086 to 225397.
Context