ianlancetaylor / demangle

C++ symbol name demangler written in Go
BSD 3-Clause "New" or "Revised" License
166 stars 24 forks source link

Add mode to ignore Rust generic type parameters #19

Closed brancz closed 1 year ago

brancz commented 1 year ago

Depending on the situation it may be too expensive to fully demangle a function name and all of its generic type parameters. In particular Rust very aggressively inlines and tries to make abstractions zero-cost, which can result in extreme nesting of generic type-parameters.

An example function name from a real life workload demonstrates this, for which a benchmark has been added. The difference of enabling/disabling the newly introduced mode is rather dramatic (even if expected since the mode intentionally does less).

$ benchstat with-generic-params.txt without-generic-params.txt
name     old time/op  new time/op  delta
Rust-10   109µs ± 0%     2µs ± 0%  -97.98%  (p=0.008 n=5+5)
ianlancetaylor commented 1 year ago

Thanks. I did this somewhat differently. I reused the existing NoTemplateParams, making it work for the Rust demangler as well. I just dropped everything inside the <>. I applied it to "dyn" entries as well.

Let me know if you see any problems. Thanks.

brancz commented 1 year ago

I don't think I feel strongly, the only thing is that now we just get empty <>, while previously we would at least see the number of type parameters taken.

Perf wise it seems identical:

$ benchstat without-types.txt without-types-no-template.txt
name     old time/op  new time/op  delta
Rust-10  2.19µs ± 0%  2.23µs ± 0%  +1.67%  (p=0.008 n=5+5)
ianlancetaylor commented 1 year ago

Yes, it seemed to me that <> was clearer than <T>. After all, there really could be a type T. And if you don't care about the type parameters, why do you care exactly how many there are?

But I'm not a Rust programmer, so let me know if I'm mistaken.