Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile, runtime: pack info into low bits of interface type pointers #26680

Open
josharian opened this issue Jul 29, 2018 · 0 comments
Open
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

Comments

@josharian
Copy link
Contributor

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:

if i.typ&15 == 0 {
  str = *i.data
} else {
  str = (i.typ&15, i.data)
}

(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):

  7.52% 117662 convT2Estring string 5
  7.09% 110979 convT2Estring string 6
  6.93% 108445 convT2Estring string 1
  5.85% 91610 convT2Estring string 3
  5.45% 85249 convT2Eslice []uint8 1 1
  4.97% 77838 convT2Estring string 4
  4.91% 76785 convT2Estring string 7
  3.78% 59191 convT2Estring string 8
  3.08% 48164 convT2Estring string 9
  3.07% 48104 convT2Eslice []uint8 0 20
  2.59% 40474 convT2Estring string 2
  2.35% 36777 convT2Islice dwarf.byChildIndex 1 1
  2.11% 33001 convT2Islice gc.methcmp 0 0
  2.08% 32491 convT2Estring string 10
  1.79% 28062 convT2Islice dwarf.byChildIndex 0 0
  1.64% 25712 convT2Estring string 11
  1.43% 22429 convT2Estring string 12
  1.43% 22339 convT2Estring string 20
  1.25% 19502 convT2Islice gc.byClassThenName 1 1
  1.20% 18828 convT2Estring string 21
  1.16% 18145 convT2Islice dwarf.byChildIndex 2 2
  1.14% 17778 convT2Estring string 13
  1.07% 16706 convT2Estring string 14
  1.06% 16523 convT2Estring string 16

This scheme would cover a lot of these.

@josharian josharian added this to the Unplanned milestone Jul 29, 2018
@ALTree ALTree added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 14, 2020
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants