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

Switch compression package (3x faster) #3

Merged
merged 2 commits into from
Nov 29, 2020

Conversation

klauspost
Copy link
Contributor

Use github.com/klauspost/compress package for compression.

Benchmarks did not actually compress since the header was carried over between calls.

Before/after are both with the benchmark fix in place.

λ benchcmp before.txt after.txt
benchmark                                          old ns/op     new ns/op     delta
BenchmarkSoleGin_SmallPayload-12                   279           284           +1.79%
BenchmarkGinWithDefaultHandler_SmallPayload-12     653           662           +1.38%
BenchmarkSoleGin_BigPayload-12                     271           284           +4.80%
BenchmarkGinWithDefaultHandler_BigPayload-12       83649         25616         -69.38%

I believe the last benchmark is the only one actually to be compressing, correct?

I didn't go out of my way to clean up the benchmark since the difference is rather obvious.

The compression ratio is likely a bit less, but among many other changes the default settings have been tweaked to give the most reasonable speed/compression tradeoff.

Use `github.com/klauspost/compress` package for compression.

Benchmarks did not actually compress since the header was carried over between calls.

Before/after with fix in place.

```
λ benchcmp before.txt after.txt
benchmark                                          old ns/op     new ns/op     delta
BenchmarkSoleGin_SmallPayload-12                   279           284           +1.79%
BenchmarkGinWithDefaultHandler_SmallPayload-12     653           662           +1.38%
BenchmarkSoleGin_BigPayload-12                     271           284           +4.80%
BenchmarkGinWithDefaultHandler_BigPayload-12       83649         25616         -69.38%
```

I believe the last benchmark is the only one actually to be compressing, correct?

I didn't go out of my way to clean up the benchmark since the difference is rather obvious.

The compression ratio is likely a bit less, but among many other changes the default settings have been tweaked to give the most reasonable speed/compression tradeoff.
Copy link
Owner

@nanmu42 nanmu42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very wow, thank you!

writerwrapper.go Show resolved Hide resolved
handler_test.go Show resolved Hide resolved
@nanmu42
Copy link
Owner

nanmu42 commented Nov 29, 2020

Benchmarks did not actually compress since the header was carried over between calls.

My bad, thanks for fix that.

I believe the last benchmark is the only one actually to be compressing, correct?

Yes, it is.

I didn't go out of my way to clean up the benchmark since the difference is rather obvious.

I will clean it up. 🤣

The compression ratio is likely a bit less, but among many other changes the default settings have been tweaked to give the most reasonable speed/compression tradeoff.

Generally speaking, is CompressionLevel = 6 a good default setting?

@nanmu42 nanmu42 merged commit 7653380 into nanmu42:master Nov 29, 2020
@klauspost klauspost deleted the switch-gzip-pkg branch November 30, 2020 09: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.

2 participants