Repository navigation
perf(index): queries read only what they answer from - #1150
Draft
16bit-ykiko wants to merge 6 commits into
Draft
16bit-ykiko wants to merge 6 commits into
16bit-ykiko wants to merge 6 commits into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
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.
Why
On a project of Unreal Engine's size, a cold
clice queryspends 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::GetWorldread 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 AActorandsymbol-search TArrread 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.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.What changed
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.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.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.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.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_variantsandInstantiationShard::has_dead_useshad 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.CompactsUnreadShardandCompactsAppendedShard: 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.pixi run check-layers.definition AActorfrom 8.6 to 5.7 s and the CLI's memory from 501 to 292 MB.