Repository navigation
fix: codegen symbol ordering with v0 mangling - #166449
paradoxicalguy wants to merge 1 commit into
Conversation
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
|
@paradoxicalguy: 🔑 Insufficient privileges: not in try users |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…<try> fix: codegen symbol ordering with v0 mangling
|
TBH, I tried this approach only to test the idea, but I don't really like it, and it was slower a bunch. I think a "proper" fix would be to sort by some precursor thing from which we compute the symbol name, before we insert the disambiguator (probably something like Also, demangling also doesn't address the issue I was trying to address - that disambiguators (hashes) and up influencing performance of code that uses symbols and transitively PGO stats (possibly). This code still has that property because we process disambiguators in mangling and demangling. |
|
yes im tinkering w more stuff locally rn, currently trying to see if |
This comment has been minimized.
This comment has been minimized.
|
r? @panstromek |
This comment has been minimized.
This comment has been minimized.
b71d09c to
bff15a2
Compare
|
replaced the demangling with a dedicated v0 mangling mode that omits crate disambiguators for the sort key. no new dependency, rustc-demangle is dropped from rustc_middle. extended the run-make test to cover distinct generic arguments (fails on upstream main, passes here). full local ui, codegen-llvm and codegen-units pass on x86_64, including the two intrinsic tests that failed on aarch64 before. known gaps: dyn types with multiple projection bounds can still vary with -Cmetadata (i have a repro), and every mono item is now mangled twice. i haven't measured that cost. |
|
Ok, this looks more like what I envisioned. I worry we're going to get a perf hit, though, let's try where we stand. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…<try> fix: codegen symbol ordering with v0 mangling
|
oh, I didn't realize the previous one didn't finish, yet. |
|
I think you will still need to include the disambiguators in the sort key to have a consistent order when two crates with the same name but different |
|
yes, the sort tuple is (sort key, full mangled symbol), so the disambiguators only matter as a tiebreaker when the primary keys are identical. that case (same-named crates with the same item) still depends on |
|
Yes @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
|
oh, the update @bors try |
This comment has been minimized.
This comment has been minimized.
…<try> fix: codegen symbol ordering with v0 mangling
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (a0f7d9d): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.2%, secondary -0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 1.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 461.503s -> 469.097s (1.65%) |
|
looked at the self-profiles. in cargo debug/full, i'll look into avoiding the redundant mangling/query work. |
|
The btw. if there's a weird result like that, it's good to run the provided cachegrind command and just double check that the diff is where you expect it to be. |
|
=O good to know! i'll keep that in mind and use cachegrind for remaining regressions |
|
ran cachegrind on cargo debug/full and reproduced the regression locally (+1.49%). 💤 for now 🛌 |
85a10ea to
451e542
Compare
|
6 cachegrinds later, regression is now +0.23% on Cargo (Debug/Full). All 1,268 selected tests pass, and linkage symbols remain unchanged in the tested workload. |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…<try> fix: codegen symbol ordering with v0 mangling
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (20458e2): comparison URL. Overall result: ❌ regressions - please read:Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. Next, please: If you can, justify the regressions found in this try perf run in writing along with @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.9%, secondary -2.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 0.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 462.454s -> 463.061s (0.13%) |
|
incr comp reaching heights unlike me 🙏 |
| // correct symbol name of instances from upstream crates. | ||
| fn symbol_name_provider<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> ty::SymbolName<'tcx> { | ||
| let symbol_name = compute_symbol_name(tcx, instance, || { | ||
| tcx.symbol_name_and_sort_key(instance).0 |
There was a problem hiding this comment.
Does symbol_name need to build the sort key at all? afaik it's queried from places that never sort like symbol export, coverage, or diagnostics, why all of them now need to pay for the extra string?
There was a problem hiding this comment.
This might have introduced some part of unnecessary regressions I guess.
There was a problem hiding this comment.
in a local prototype symbol_name is now just an accessor on the combined query (no wrapper query), which cuts the regex enum-reorder regression from +1.67% to ~+0.13%. but linkage-only callers still pay for the sort key. i'm looking at making that lazy without a second full mangle
|
i've managed to reduce the local regex enum-reorder regression from +1.67% to +0.135% by consolidating both queries into a single disk-cached query. cargo incremental still shows ~0.4–0.5% overhead. correctness tests and linkage comparison passed locally. official perf is still pending. |
|
Could the query only return the linkage plus the ranges where the disambiguators were written, instead of a second buffer? In your pr I found the key only differs in the |
View all comments
fixes #152910
sort codegen items using a dedicated v0 mangling key that omits crate disambiguators, reducing the dependence of symbol ordering on
-Cmetadatawithout changing actual linkage symbols.adds a run-make regression test covering distinct function paths and generic arguments, verified with A/B testing against upstream.
based on the original work in #162003 by @panstromek