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

some problem about gzip writer not use sync pool in middleware/compress.go #1643

Closed
imxyb opened this issue Sep 22, 2020 · 1 comment · Fixed by #1672
Closed

some problem about gzip writer not use sync pool in middleware/compress.go #1643

imxyb opened this issue Sep 22, 2020 · 1 comment · Fixed by #1672

Comments

@imxyb
Copy link
Contributor

imxyb commented Sep 22, 2020

Looking at the git commit history, I found that the sync pool of the gzip writer was removed. The reason is to fix the issue here: labstack/armor#13. But I still don't understand the reason for this deletion. I guess tha Is it because there is no way to return an error when using sync pool?

the removed code:

func gzipPool(config GzipConfig) sync.Pool {
	return sync.Pool{
		New: func() interface{} {
                        // can not return error here
			w, _ := gzip.NewWriterLevel(ioutil.Discard, config.Level)
			return w
		},
	}
}
pafuent added a commit to pafuent/echo that referenced this issue Nov 7, 2020
Adding a sync.Pool for the *gzip.Writer reduces the allocations of the
Compress middleware in 50% and gives an increase on execution speed of
a 85%
This fix labstack#1643
@pafuent
Copy link
Contributor

pafuent commented Nov 7, 2020

I did the change and I could see some improvements on the speed and the number of allocations. Please take a look at the PR and check that the implementation makes sense.

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 a pull request may close this issue.

2 participants