chore: optimize maps.Values and maps.Keys #17
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR optimizes the performance of maps.Values and maps.Keys (around 125 usages in sidero code) by using the internal runtime functions runtime.keys and runtime.values. There is strong desire in Go Team to disable
go:linkname
usage in user code 1, but this is a special case where we usePush
linkname
pattern which is said to be supported in the future. It is tested with both Go 1.22 and latest Go with CL 585556 2 applied.To futher future-proof this code, we have added a build tag
go1.22 && !go1.24
to ensure this code is only compiled with Go 1.22 and 1.23 and falls back to the old implementation for Go 1.24 and above. This is because we don't know yet ifruntime.keys
andruntime.values
are going to be present in Go 1.24. We will update this code when Go 1.24 freeze happens.Benchstat results (overall 26% CPU usage reduction):
Footnotes
https://github.com/golang/go/issues/67401 ↩
https://go-review.googlesource.com/c/go/+/585556 ↩