Skip to content

perf(index): queries read only what they answer from - #1150

Draft
16bit-ykiko wants to merge 6 commits into
mainfrom
perf/query-reads
Draft

16bit-ykiko wants to merge 6 commits into
mainfrom
perf/query-reads

Conversation

@16bit-ykiko

@16bit-ykiko 16bit-ykiko commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Why

On a project of Unreal Engine's size, a cold clice query spends most of its time reading the index database, and much of what it reads never reaches the answer. Measured on Unreal Engine 5.8, by the pages of the database file each cold query touched:

  • references AActor::GetWorld read 262 MiB of symbol records. Each reference is shown with the function enclosing it, and to find that function the query asked the symbol record of every definition in each referencing file whether it is a function.
  • symbol-search AActor and symbol-search TArr read 48 and 78 MiB of instantiation shards. Placing each candidate at its definition opened the instantiation shard of the file it looked in, though the definition is in the file's own shard.
  • An unqualified name (definition AActor) went through the fuzzy ranking, which reads the record of every symbol the pattern fuzzily matches, before keeping only the ones spelling the name exactly.
  • Every shard read from the database also read its file's dependents record, to mask the variants no unit contributes any more, of which a stored shard holds none.

What changed

  • Enclosing functions (feature/hierarchy.cpp): a file's definitions are collected by their extents alone. For a site, the definitions around it are taken innermost first, and the index is asked whether each is a function until one is, each symbol once per file.
  • Instantiation shards when a walk reaches them (index/query): a relation walk over the disk shards reads a file's instantiation shard only when it goes on past the shard's own relations; a walk stopping at a definition reads none. serving(file, /*instantiations=*/false) gives a source without them, which the walk, the reference lines' text and the enclosing functions use.
  • Exact name first (index/query/locate.cpp): a fuzzy pattern is first looked up as an exact name. When some symbol spells it, case included, those symbols answer alone, as they did when the fuzzy ranking found them; only when none does is the fuzzy ranking run.
  • Dependents only for marked shards (index/project_index): a stored shard holds live variants and uses alone, except where a merge since marked its file for the next save; only those are masked as they are read, which reads the dependents record.
  • Compaction judged by the stored data (index/project_index/save.cpp): a save compacts a marked file's shard and instantiation shard when they store a variant or use outside the file's live sets, compared directly, not by the mask the copy in memory carries. A shard the save reads for the first time carries none, nor does the copy a merge makes when it appends a variant to a shard holding a dead one; with the reads above unmasked, judging by the mask would have kept their dead variants on disk and served them. Shard::has_dead_variants and InstantiationShard::has_dead_uses had no other use and are gone.

Tests

  • QueryReads (new) opens a saved index with its reads logged and pins what each query reads: placing a symbol reads its file's shard, and neither the instantiation shard nor the dependents record; an exact name reads one symbol record; the enclosing function and the reference's line read the record of that function alone and no instantiation shard; a walk going past a shard reads its instantiation shard and no dependents record. Each check fails without the change it pins.
  • ProjectIndexSave.CompactsUnreadShard and CompactsAppendedShard: a save compacts a shard it reads first, and one a merge appended to while it held a dead variant. Both keep the dead variant when the save judges by the mask.
  • IndexSearch.ExactSpellingAnswersAlone: the answer for a name some symbol spells exactly, and for one no symbol does.
  • Linux x64 RelWithDebInfo and Debug unit tests and cases, Windows x64 unit tests, pixi run check-layers.
  • Measured on Unreal Engine 5.8 (Linux, cold page cache), on a build that also skipped verifying records as it read them: the exact-name lookup took definition AActor from 8.6 to 5.7 s and the CLI's memory from 501 to 292 MB.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
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.

1 participant