Re: [PATCH 0/5] perf symbol: Speed up demangling of long Rust symbols
From: Namhyung Kim
Date: Tue Oct 06 2026 - 16:11:05 EST
On Mon, Sep 28, 2026 at 02:02:22AM +0100, Michal Pluta wrote:
> 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
Reviewed-by: Namhyung Kim <namhyung@xxxxxxxxxx>
Thanks,
Namhyung
>
> 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
> --
> 2.43.0
>