fix(workspace): settle gathers on first read instead of inside the edit - #537
Merged
Merged
Conversation
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
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.
What and why
Since #316,
Workspace.Updateran the gather cascade (Gathers.Regather→mosaUnion→mosaAudit.kindOf/FeatureTypeSetover every symbol of the edited document, on a just-invalidated resolver) eagerly under the write lock.BenchmarkWorkspaceEdit/vehiclewent 44.7 ms → 99.6 ms between v0.8.1 and develop whilevehicle/reindex+diagnosticsstayed flat (137 → 135 ms): the work moved from the first diagnostics read into every edit, i.e. onto every keystroke in the LSP.The regather is now queued instead of run:
settlingguards the re-entry throughcontextLocked → semanticsLocked;invalidateAllLockedclears the queue. Every reader ofresolver/model/diagCache/refsgoes through one of the three settle points, and none of theRLockpaths reach them, so settled state is only mutated under the write lock and every read sees exactly what it saw before — computed on the first read after an edit rather than inside it. Multiple edits before a read coalesce into one settle.How it was verified
TestLazyRegatherCoalescesUpdates(two updates, no read between; diagnostics match a fresh workspace with the same content); existingTestWorkspaceUnionJudgmentFollowsAnotherDocumentcovers the single-edit case.go test ./internal/workspace/... ./internal/check/... ./internal/frontend/lsp ./internal/frontend/repl,-raceoninternal/workspace/modelandinternal/frontend/lsp.WorkspaceEdit/vehicle99.6 ms → 43.7–49.3 ms (v0.8.1: 44.7 ms);vehicle/reindex+diagnosticsunchanged at ~135 ms;WorkspaceEditSmallDocBesideLarge, LSPReferences*/WorkspaceUpdateunchanged.Checklist
make testandmake lintpass locallychanges/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.mdmake docs-countsrun if a gate count moved (compliance rows need nothing: the census is counted at docs build)F4,K5) in the body, docs, or changelog