cmd/compile, runtime: pack info into low bits of interface type pointers #26680
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Performance
Milestone
We've generally avoided doing any bit packing, so I don't anticipate this happening, but wanted to record the idea for reference and in case it generates interesting discussion.
We could pack some information into the bottom bits of interface type pointers. As long as
sizeof(reflect.type) % 16 == 0
, it'll point within the same object, so there should be no GC impact.For example, for strings with 0 < len <= 15, instead of
(*typ, *str)
we could have(*typ + len(s), str.ptr)
.Then
i.(string)
ends generating code like:(Note that strings of length 0 are already allocation-free by pointing into runtime.zero.)
You could do something similar for small ints and tiny slices (2 bits each for len, cap-len).
The impact of this would be fairly localized, I think--just type switches, interface assertions, interface equality checks, and some choice bits of the runtime.
For reference, over make.bash, here are percents, counts, types, and length (and caps for slices) of calls to
convT2(E|I)(string|slice)
:This scheme would cover a lot of these.
The text was updated successfully, but these errors were encountered: