v0 mangling should avoid backrefs when they're not shorter than their target. #87511
Labels
A-linkage
Area: linking into static, shared libraries and binaries
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
I-heavy
Issue: Problems and improvements with respect to binary size of generated code.
While working on #61486 / #87194 I came across backrefs in byte array values (with repeating elements), which I hadn't thought about (in terms of implications on optimizing the length of a symbol), but which is otherwise entirely expected. In order to demonstrate an edge case, I encoded
some...longer...path::<{ &[0, 0, 0, 0] }>
to getKRAh0_B12_B12_B12_E
, which is parsed as follows:Because this is a long enough symbol, the backrefs end up being (at least) 4 bytes each (to encode positions greater than 62), whereas an integer leaf constant with a
0..=15
value gets encoded as 3 bytes, so the backrefs are each adding an extra byte (and making more pointless work for the demangler).We could avoid this by tracking the range, not just the start, of an encoded path/type/const, and one of:
print_backref
decide between actually printing the backref, and duplicating the contents of that range, inline, depending on which would be shorterHowever, this isn't an urgent concern IMO because of the combination of these aspects:
62
or62² = 3844
, respectively)impl
on a builtin type, using a backref for theimpl
parent module)&str
isRe
,[u8]
isSh
,fn()
isFEu
, etc.)It might be interesting to measure the size difference across some larger projects (including
rustc
and Cargo), by making this change (even inefficiently), after v0 becomes the default, but I don't expect a difference bigger than a handful of bytes per symbol, if that.cc @michaelwoerister
The text was updated successfully, but these errors were encountered: