-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom GreenElement #35
Conversation
This means &GreenNode and ptr::NonNull<GreenNode> are fat pointers, but ArcGreenNode and more importantly GreenElement (where it matters) store erased thin pointers and recover the length from the header.
rust-lang/rust-analyzer#2182 confirms that this decreases rowan memory usage, with The latest commit returns This passes @matklad I believe this is ready for review now. I think we should leave the |
@CAD97 did you by any change do any measurements of how effective the interning is? Ie, if we parse something like the old, non-split version of parser.rs from rustc, how many tokens and nodes are there, and which proportion of tokens is deduped? "30MB >18MB > 9MB" size reduction looks super sweet, up to the point it's hard to believe in :) It would be cool to double-check it with back-of-the-envelope calculations |
It's also interesting that |
We also completely encapsulate the dependency as well as the fact we use a thin ArcGreenNode internally.
This now uses thin-dst. It could use some cleanup, but it also fully encapsulates |
Back-of-the-envelope space savings calculation:
So an extremely conservative low-effort estimation puts this at at least a 20% memory savings. For a better estimation, we should hook ra analysis-stats to print an estimation of the full node count. A quick way would be to just annotate the cache to log cache hits and misses. So, @matklad, if this all looks good to you, I'll publish version 1.0.0 of thin-dst (transfer ownership to the rust-analyzer org?) and bump this PR to depend on that so we can start realizing these benefits. |
It'd still be cool to make |
Yeah, the approach sounds like something we should just do! Publishing 1.0 of thin-dst seems like a good first-step. I haven't looked at this PR closely, but one thing we want to do is to declare GreenNode like |
BTW, I've finished most of crucial refactorings in rust-analyzer for the time being, so I'd love to prioritize this work! |
I've got two essays due tomorrow (😨) but after that I can definitely finish this up real quick. |
This patch cannot be semver-compatible, as That said, I've come around to fully encapsulating the arc in |
Oh, good catch! I should have exposed
|
As an aside, one of the lessons from iterating through a doesn of design for syntax trees is that enums are a very easy way to expose impl details in a way you can't just fix later |
Now that we know the proper direction to take this in (and it needs to be completely refactored to do as such), I'm closing this to PR more piecewise improvement where possible. The intent is to PR the breaking changes and then make the thin-dst backend refactor entirely encapsulated. |
That's an excellent idea! I'll publish it and make a PR to rust-analyzer, so that we can trivially compare perf |
Implements a thin-pointer version of
GreenNode
and uses that to implement a 1×usize
GreenElement
. We do not yet apply any manual niching toSyntaxElement
, though it still could be niched to 2×usize
at zero performance cost.We provide a
match_element!
macro that allows for (what looks like) pattern matching overGreenElement
even though it is no longer an enum.This passes miri! 🎉 We should probably add miri to CI to make sure it stays that way.