Repository navigation
Conversation
Checkpoints share the objects of the catalog instead of copying them, a document keeps at most 16 checkpoints, and the walks of all documents together keep at most 50,000 statements and 256 checkpoints: beyond that, the caches of the least recently used documents are dropped and recomputed on the next request. A test with a counting allocator checks the memory of the editor features on many large documents.
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.
Stacked on #931.
The walk cache from #930 had no memory bound. Every checkpoint deep-copied the catalog's objects, a document could keep up to 32 checkpoints, and nothing limited the cached references across documents. With 20 open migration files of 5,000 statements each, hover, inlay hints and semantic tokens kept 734 MiB.
Caches this stack owns
Catalog(maps of the objects the file changed; the objects are now shared throughArc),Session, section statemax(64, statements / 16)top-level statements2 × statements + 1024. ≤ 50,000 statements across documentsArc<Snapshot>the walk started fromArc<Document>held by a running requestThe CLI doesn't use any of these.
checkandformatnever walk for editor features, andFileGuardcloses each file after it is processed.What changed
Catalog'sEntry::Definedholds anArc. Clones of the catalog (checkpoints, and savepoints, which clone it too) share the objects, and a change copies only the changed object.CHECKPOINTS_PER_DOCUMENT_MAX = 16: the checkpoint interval grows with the file. When the interval changes and there are too many checkpoints, the ones that no longer fall on it are dropped first, then the earliest.CACHED_STATEMENTS_MAX = 50_000andCHECKPOINTS_MAX = 256across documents (inEditorWalks). After each walk, the caches of the least recently used other documents are dropped until all caches are within budget. Caches that another request is using are skipped. A single document over the statement budget drops its own references. Each eviction is logged at debug level, and the next request recomputes the walk, so results don't change.EditorWalks::remove/clear.Measurements
crates/pgls_workspace/tests/memory_tests.rsuses a counting#[global_allocator]. It opens N documents of M statements (migration-style: table, index, SQL function with body, query), and on each runs diagnostics, hover at the end, inlay hints and semantic tokens for the whole file, and code actions. It reports the peak and the memory with all documents open over a baseline taken after a warmup, plus the editor features' share (what hover, hints, tokens and code actions keep on top of what diagnostics keep), and the memory left after closing them all. It asserts editor features < 128 MiB, peak < 1 GiB and retained < 16 MiB. The default is 20 × 1,000, which takes about 30 s in debug;MEMORY_DOCUMENTS/MEMORY_STATEMENTSchange it.The rest of the memory with all documents open is the per-document statement caches (AST, CST, annotations): about 21 MiB per 1,000-statement document on this branch. Lane A bounds those across documents on main (#913/#929). What remains after closing is the one-entry hover snapshot cache (
snapshot_before), which #913 also replaces. When the stacks meet, the walk cache and those caches should use one budget mechanism (one LRU of documents, one notion of cost) instead of two.Tests
test_editor_walk_cache_budget: three 3,000-statement documents keep at most 16 checkpoints each; a budget a bit over one document keeps only the most recently used cache; evicted documents give the same tokens on the next request; closing drops everything.memory_testsas above. Catalog tests, the Postgres regression suite and the analyser specs pass with the shared entries.Not covered