Skip to content
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

self-profile: Cache more query key strings when doing self-profiling. #75452

Merged
merged 1 commit into from
Aug 14, 2020

Conversation

michaelwoerister
Copy link
Member

This PR adds optimized SpecIntoSelfProfilingString implementations for two common query key types (LocalDefId and WithOptConstParam). This makes raw self-profiling data on disk 8-9% smaller for my two test cases (regex and cargo).

The on-disk format is not affected, so no tooling updates need to happen.

I also tried adding an impl for Ty<'tcx> (which should reduce size quite a bit) but the compiler did not allow me to add a specialized impl parameterized with 'tcx. I don't know if there is an actual problem with that or if the implementation of specialization just doesn't support it yet.

cc @wesleywiser @Mark-Simulacrum

@rust-highfive
Copy link
Collaborator

r? @lcnr

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 12, 2020
@Mark-Simulacrum
Copy link
Member

cc @matthewjasper on the specialization of Ty<'tcx> -- I suspect we're not allowing that because lifetimes are hard, i.e., it's a limitation of the compiler? Is there some way we could work around that?

// "WithOptConstParam { did: foo::bar, const_param_did: Some(foo::baz) }"
// becomes "(foo::bar, foo::baz)" and
// "WithOptConstParam { did: foo::bar, const_param_did: None }"
// becomes "(foo::bar, _)".
Copy link
Contributor

@lcnr lcnr Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does self profiling need the WithOptConstParam for?

You probably want to uniquely identify query calls? Considering that self.const_param_did should be unique for each DefId (as we otherwise cause an ICE while building mir) you might also be able to store this as (did, bool) for some additional wins.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does self profiling need the WithOptConstParam for?

Some queries (e.g. mir_build) take WithOptConstParam values as keys. Since self-profiling can record a string representation for each query key that gets used some of those keys will be stringified WithOptConstParam values. You can find the full list of queries (and their keys) in https://github.com/rust-lang/rust/blob/master/src/librustc_middle/query/mod.rs.

You probably want to uniquely identify query calls? Considering that self.const_param_did should be unique for each DefId (as we otherwise cause an ICE while building mir) you might also be able to store this as (did, bool) for some additional wins.

I'm not quite sure I follow. You are saying that there is an invariant around const_param_did that makes sure that it is always the same (or None) for a given did value?

In any case, I think it's a good idea to keep this as close to the original value as possible. The encoding format should make sure that there is no data redundancy (assuming that that DefId was already mentioned somewhere already).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since self-profiling can record a string representation for each query key that gets used

That's what I wasn't sure about, thanks 👍

I'm not quite sure I follow. You are saying that there is an invariant around const_param_did that makes sure that it is always the same (or None) for a given did value?

yes.

In any case, I think it's a good idea to keep this as close to the original value as possible. The encoding format should make sure that there is no data redundancy (assuming that that DefId was already mentioned somewhere already).

👍

Copy link
Member

@wesleywiser wesleywiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me. Thanks @michaelwoerister!

// "WithOptConstParam { did: foo::bar, const_param_did: None }"
// becomes "(foo::bar, _)".

let mut components: SmallVec<[StringComponent<'_>; 8]> = SmallVec::new();
Copy link
Member

@wesleywiser wesleywiser Aug 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be a SmallVec<[StringComponent<'_>; 5]>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we even need a smallvec? Wouldn't a simple array work here? ([StringComponent<'_>; 5])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, that's true. I'll change that.

@lcnr
Copy link
Contributor

lcnr commented Aug 13, 2020

while I am not too familiar with self-profile, this looks good to me and @wesleywiser already approved, so

@bors r+

@bors
Copy link
Contributor

bors commented Aug 13, 2020

📌 Commit 08d9517 has been approved by lcnr

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2020
@michaelwoerister
Copy link
Member Author

Thanks for the review!

@wesleywiser
Copy link
Member

We don't profile in verbose mode in perf.rlo so this shouldn't have any effect on our measurements.

@bors rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 14, 2020
Rollup of 12 pull requests

Successful merges:

 - rust-lang#74650 (Correctly parse `{} && false` in tail expression)
 - rust-lang#75319 (Fix ICE rust-lang#75307 in `format`)
 - rust-lang#75417 (Don't spill operands onto the stack in naked functions)
 - rust-lang#75452 (self-profile: Cache more query key strings when doing self-profiling.)
 - rust-lang#75459 (fix LocalInfo doc comment)
 - rust-lang#75462 (Remove unused tcx parameter)
 - rust-lang#75467 (Fix E0741 error code explanation)
 - rust-lang#75471 (Change registered "program name" for -Cllvm-args usage messages)
 - rust-lang#75477 (Expand function pointer docs)
 - rust-lang#75479 (make rustc-docs component available to rustup)
 - rust-lang#75496 (Prioritization WG: Open Zulip topics only for `I-prioritize` issues)
 - rust-lang#75500 (Disable zlib in LLVM on aarch64-apple-darwin)

Failed merges:

r? @ghost
@bors bors merged commit 6f964f0 into rust-lang:master Aug 14, 2020
@cuviper cuviper added this to the 1.47.0 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants