Conversation
ZeWaka
marked this pull request as ready for review
October 2, 2026 07:48
Owner
|
I'm not a fan of double-parsing. I'd prefer to put proc bodies in some set-aside heap so that dropping them afterwards actually works. Maybe we should let this ride until custom allocators stabilize in Rust 1.100. |
Contributor
Author
I looked into this a little bit but it seemed like it'd be a lot of code churn, maybe having to add lifetimes to the AST. |
Contributor
Author
|
Superseded by #487, which puts proc bodies in a seperate mimalloc heap instead of double-parsing. |
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.
Depends on #484, this is based off of it (otherwise there's a regression in Linux memory usage).
The langserver now keeps proc bodies out of the object tree it holds onto during idle.
The main thread parses without proc bodies, which is what hover, completion, goto, etc. use.
At the same time a background thread does the full parse, sends the diagnostics, runs dreamchecker, builds the Find References table, and then throws its tree away.
It's not just as easy as dropping the proc bodies after dreamchecker because their allocations are mixed into the same pages as the data we keep.
Diagram
A thick border means it's kept in memory while idle
flowchart TD S[Load or reparse] --> M1 S --> B1 subgraph main[Main thread] M1[Parse, skipping proc bodies] --> M2[Object tree<br/>for hover, completion, goto] end subgraph bg[Background thread] B1[Full parse, with proc bodies] --> B2[Send parse errors] B2 --> B3[Build Find References table] B3 --> R[Find References table] end subgraph dc[Dreamchecker thread] D1[Check procs] --> D2[Send dreamchecker errors] end B2 -->|starts| D1 B3 --> F[Full tree freed once both are done] D2 --> F classDef kept stroke-width:3px class M2,R keptMedian of 3 runs each on my local Windows machine:
Percentages are vs #484. Similar percentages on WSL.
Thoughts
The main downside is a higher peak on the first load, since both parses are in memory at once for roughly the last third of the load. However, reparses actually peak lower than #484.
If the higher peak on the first load is a problem, a langclient setting to opt out of this could help users on memory-constrained systems.
Related: #113