-
Notifications
You must be signed in to change notification settings - Fork 181
Add API to dump memory usage #916
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
Add API to dump memory usage #916
Conversation
✅ Deploy Preview for salsa-rs canceled.
|
CodSpeed Performance ReportMerging #916 will not alter performanceComparing Summary
|
4a3497a
to
e1293de
Compare
e1293de
to
090523a
Compare
Sorry, I didn't get to reviewing this today. I plan to review tomorrow. Note, there's a test failure on 1.85 |
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.
This is great. I think it would be good to gate this behind the unstable feature for now.
It would be nice if we could extract the query name somehow. I left a few ideas but not surehow (and I'm not very familiar with that part of the code). Maybe @Veykril or @davidbarsky have an idea of how we could do that?
src/database.rs
Outdated
/// | ||
/// The returned map holds memory usage information for memoized values of a given query, keyed | ||
/// by its `(input, output)` type names. | ||
pub fn queries_info(&self) -> HashMap<(&'static str, &'static str), IngredientInfo> { |
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 don't have a concrete proposal but I was just wondering if we could somehow use Zalsa::memo_ingredient_indices
or maybe the jar_map
(by indexing with the erased type id) to get the query ingredient index.
src/database.rs
Outdated
@@ -132,4 +134,99 @@ impl dyn Database { | |||
let views = self.zalsa().views(); | |||
views.downcaster_for().downcast(self) | |||
} | |||
|
|||
/// Returns information about any Salsa structs. | |||
pub fn structs_info(&self) -> Vec<IngredientInfo> { |
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.
maybe call this ingredients
?
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's not all ingredients, it's only tracked/interned/input structs.
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.
That’s the big three, no? We’d be missing supertypes?
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.
Queries are also ingredients but they're split out from this method.
Internally there's also a bunch of other things that we call ingredients, but I'm not sure that's relevant for this API (tracked struct fields, etc.).
I'm trying to remember, but I also remember struggling with this when I last touched this. |
@carljm any chance you know how to get the query name? |
Not off the top of my head, no, I'd need to spend some time looking at it. |
The problem is that memos are stored on the input ingredients, which are completely disconnected from the query ingredient. I think the only way to do this would be to store the type name on |
This PR adds the methods
<dyn Database>::{structs_info, queries_info}
, which allow accessing memory usage information about salsa structs and memos. In ty, this lets us generate a report that looks like this:One current limitation is that we cannot provide the name of the query function, only it's input and output types. The other is that this only reports the stack size of any struct fields, which makes this a lot less useful for anything even wrapped trivially in a
Box
orArc
. Ideally we would have some way of asking a type for it's heap allocation size (maybe using something like theget-size
crate), but it would likely have to be opt-in to avoid breakage, and I'm not sure exactly how that would look (maybe a macro attribute, or feature flag?).I'm not sure how others have been profiling salsa-related memory usage, but the above report has been extremely useful for us. Also unsure if this should be under the
salsa_unstable
feature.