Boosting String and Bytes Conversions Speed by 140x with Zero Allocation in Go

Converting between a string and bytes requires allocating new memory. However, strings and bytes (which are essentially slices of bytes) share a similar memory structure. The main difference is that a slice can grow as needed, while a string remains immutable. We can gain insights into their internal structures by referring to the Go documentation. Strings are defined using StringHeader, while slices are defined using SliceHeader. To enhance clarity, we’ll include these definitions here:...

October 21, 2023 · 4 min · 706 words · Jose Sitanggang