-
Notifications
You must be signed in to change notification settings - Fork 1.9k
perf: Use one query per crate for lang items, not one per lang item #21149
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
Conversation
Via separate methods. This is both more clear, shorter, and will be required for the next commit.
| } | ||
| "#, | ||
| expect![[r#" | ||
| me random_method(…) (use dep::test_mod::TestTrait) fn(&self) DEPRECATED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do something about this test, the order changes every now and then.
24c68f5 to
d3d0845
Compare
Lang items rarely change, so putting a query for each doesn't give us anything. On the other hand, putting them behind only one query not only saves memory, it also has a giant benefit: we can store the struct with all lang items in the interner, making access to them very cheap. That basically means that anything in the hot path can avoid a *very common* query, and exchange it for a simple field access.
d3d0845 to
d9bee82
Compare
|
So I checked and this saves 7mb. Cute. Speed impact is more real. (However thinking about it it's amusing: those 7mb were likely caused, almost all of them, only by query dependencies!) |
| /// Salsa query. This will look for lang items in a specific crate. | ||
| #[salsa_macros::tracked(returns(ref))] | ||
| pub fn crate_lang_items(db: &dyn DefDatabase, krate: Crate) -> Option<Box<LangItems>> { | ||
| pub fn crate_lang_items(db: &dyn DefDatabase, krate: Crate) -> LangItems { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep the Option<Box<_>> here, 99.9% of all crates will have this by completely empty after all, unlike the lang_items query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't really matter and makes the code a tad more complicated, having few extra kilobytes per crate won't matter for memory usage.
Lang items rarely change, so putting a query for each doesn't give us anything. On the other hand, putting them behind only one query not only saves memory, it also has a giant benefit: we can store the struct with all lang items in the interner, making access to them very cheap. That basically means that anything in the hot path can avoid a very common query, and exchange it for a simple field access.
This saves 3 seconds on analysis-stats on self. I can't measure the impact on memory as it fluctuates wildly due to some recent changes, but I believe the impact will be positive, and definitely not negative.
Reviewing commit-by-commit is recommended. The first commit is more technical and could use a skim review.