I created these benchmarks for an article in Norwegian:
I gained some insight into this while writing this. I’m not sure how portable the unsafe-package in Go is, but I did some tests, and there are about 10% to save (deliberately not saying what to save) by doing unsafe []byte to string conversion of some vital parts of Hugo. It might not be worth it (too unsafe), but it’s interesting.
Also have a look at the “memory free” string append to []byte. Got that from a tweet.
It improves the result but unsafe case is still faster than safe case.
Using unsafe would improve the performance but we should take care to keep an original string or []byte is there, not to be collected by GC while using it and also to ensure not to be modified by the other goroutine.
I think using it with function local vars is safe.