perf symbol: Speed up demangling of long Rust symbols
Status from this message: Thanks, applied the first two patches to perf-tools-next, for v7.4.
Get series with b4
b4 am [email protected]Versions newest first
Patches in v1 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | perf test demangle: Fail when demangling failstools/ tools/ | +2 | 1 reply | |
| 2/5 | perf symbol: Don't return an unterminated Rust demangle buffertools/ | +5 | 2 replies | |
| 3/5 | perf symbol: Grow the Rust demangle buffer geometricallytools/ tools/ | +20 | 4 replies | |
| 4/5 | perf symbol: Shrink the demangled Rust buffer to fittools/ | +4 | 1 reply | |
| 5/5 | perf symbol: Move Rust demangling into its own functiontools/ | +35 | 0 replies |
Reviews trailers per patch
2 of 5 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.
| Patch | Ian Rogers | Namhyung Kim |
|---|---|---|
| Series | R-b | |
| 1/5 | R-b | |
| 2/5 | R-b | |
| 3/5 | ||
| 4/5 | ||
| 5/5 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 0/5] perf symbol: Speed up demangling of long Rust symbols
dso__demangle_sym() demangles Rust v0 symbols itself instead of using a helper like the other demanglers. When a demangled name doesn't fit the buffer, it grows the buffer by a fixed 32 bytes and reformats the whole name from scratch. The number of attempts grows with the name's length, so the total work is quadratic. Rust programs with deeply nested generics can have very long demangled names, and I noticed this as real time spent in perf report on perf.data recorded from launching Bevy and Typst.
Patch 3 is the actual optimisation, doubling the size of the buffer instead. Patch 5 moves the Rust-specific logic into its own function, matching how the other demanglers are called. I think the cleanup is worthwhile but I understand it comes down to personal taste and the patch can be skipped if maintainers would rather keep dso__demangle_sym() as is.
I used an LLM to review my patches and find the issues with the demangle tests and the unterminated buffer bug.
Testing:
- 'perf test' passes, including the demangle Java, OCaml and Rust suites (patch 3 adds a case for a symbol that exceeds the buffer limit).
- 'perf report' output is unchanged before and after this series on every Rust binary I tried it on.
- Built and tested on x86-64 with a 7.0 kernel.
The series is based on perf-tools-next, commit 0ae6fc78c5ce ("perf
timechart: Remove the unused use_old_power_events variable").
Michal Pluta (5):
perf test demangle: Fail when demangling fails
perf symbol: Don't return an unterminated Rust demangle buffer perf symbol: Grow the Rust demangle buffer geometrically perf symbol: Shrink the demangled Rust buffer to fit perf symbol: Move Rust demangling into its own function
tools/perf/tests/demangle-java-test.c | 1 + tools/perf/tests/demangle-rust-v0-test.c | 13 +++++ tools/perf/util/symbol.c | 60 +++++++++++++++--------- 3 files changed, 52 insertions(+), 22 deletions(-)
base-commit: 0ae6fc78c5ce0dfd18d8712a50f0fd4602eff103
Signature · 1 line
2.43.0