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

Improve performance by reducing allocations #17

Closed
wants to merge 1 commit into from

Conversation

itchyny
Copy link
Contributor

@itchyny itchyny commented Jan 12, 2021

I suggest improving the performance by using bytes.Buffer. Creating much string leads to such an overhead to both ns/op and allocations. This p/r also fixing too much json.Encoder for each map keys. Unlike #16, this p/r is safe in multiple goroutines. Note that this pr still depends on unsafe package but we can wait for fatih/color#124 to be resolved. Or if you don't like this changes, you can close.
Performance difference is significant as follows.

benchmark              old ns/op     new ns/op     delta
BenchmarkFromat-16     12615         5766          -54.29%

benchmark              old allocs     new allocs     delta
BenchmarkFromat-16     191            50             -73.82%

benchmark              old bytes     new bytes     delta
BenchmarkFromat-16     6103          3033          -50.30%

@itchyny itchyny force-pushed the reduce-string-allocations branch 3 times, most recently from d7ea737 to f0349de Compare January 13, 2021 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant