Skip to content

LocalStore: Reduce number of SQLite calls - #574

Open
edolstra wants to merge 4 commits into
sync-2.35from
fewer-sqlite-calls
Open

LocalStore: Reduce number of SQLite calls#574
edolstra wants to merge 4 commits into
sync-2.35from
fewer-sqlite-calls

Conversation

@edolstra

Copy link
Copy Markdown
Collaborator

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

edolstra added 3 commits July 22, 2026 12:09
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>
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a9c52418-d4a7-4e29-929c-3fa9fd6378e1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fewer-sqlite-calls

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

@github-actions
github-actions Bot temporarily deployed to pull request July 22, 2026 14:34 Inactive
@edolstra edolstra changed the title Fewer sqlite calls LocalStore: Reduce number of SQLite calls Jul 22, 2026
@github-actions
github-actions Bot temporarily deployed to pull request July 22, 2026 17:02 Inactive
@github-actions
github-actions Bot temporarily deployed to pull request July 23, 2026 10:25 Inactive
@edolstra
edolstra force-pushed the fewer-sqlite-calls branch from 04fe233 to b800e65 Compare July 23, 2026 11:30
@github-actions
github-actions Bot temporarily deployed to pull request July 23, 2026 11:33 Inactive
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.

2 participants