-
Couldn't load subscription status.
- Fork 144
Improve performance of token compilation #12
Conversation
|
Is this also the case upstream @estensen ? Maybe it'd make sense to contribute there too |
|
Correct me if I'm wrong |
|
Yeah, planning to upstream this as well :) As far as I understand, it doesn't matter if you add a byte (converted to string) or a longer string. The string builder will append one item per iteration and it's the number of items that causes re-allocation of slices and not the length of the items. |
|
I'm getting my feet wet here. How many tokens are typically compiled? Running benchmarks locally growing the string builder is faster from around 25 items. |
|
https://github.com/estensen/benchmarks/blob/master/encoding/encoding.go |
|
Sounds good. |
📝 Summary
hex.EncodeToStringto convert bytes to hex📚 References
strings.Builderis backed by a slice, soGrow()pre-allocates this slicehttps://cs.opensource.google/go/go/+/refs/tags/go1.19.3:src/strings/builder.go;l=15
TODO: Add benchmark
CONTRIBUTING.md