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

Reduce allocations in per-request methods to improve performance #395

Merged
merged 3 commits into from Mar 27, 2019

Conversation

smarterclayton
Copy link
Contributor

As part of performance evaluations in Kubernetes go-restful was a
significant source of time and more importantly memory allocations
during request processing. Profiling uncovered a number of places
where some specific changes could be made to avoid allocating which
reduces CPU use during garbage collection on per-request actions.

The following three changes were the smallest / easiest and should
be relatively easy to review. There are other hot spots that still
need to be investigated which may require more aggressive changes.

Reduce allocations in route selection

The use of new arrays for each phase of detectRoute can be simplified: each
pass filters the existing array and whatever is left at the end is
returned. While somewhat harder to read, this method is a significant
source of allocations.

Reduce allocations in Accept and Content-Type matching

The mime handling methods can do a single pass over the header without
needing to allocate. This improves performance of these methods in higher
traffic API servers.

Prevent additional allocations when sorting routes for selection

Use of an uninitialized array and the use of sort.Reverse cause extra
allocations in request routing which are unnecessary.

Use of an uninitialized array and the use of sort.Reverse cause
extra allocations in request routing which are unnecessary.
The mime handling methods can do a single pass over the header without
needing to allocate. This improves performance of these methods in
higher traffic API servers.
The use of new arrays for each phase of detectRoute can be simplified:
each pass filters the existing array and whatever is left at the end
is returned. While somewhat harder to read, this method is a significant
source of allocations.
@smarterclayton
Copy link
Contributor Author

@wojtek-t FYI

@emicklei
Copy link
Owner

@smarterclayton thank you for your effort and work to improve the performance.

To be honest, I did not spent time on measurements to see where it can be improved.

I will review your changes carefully.

@emicklei emicklei merged commit 8673ba5 into emicklei:master Mar 27, 2019
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.

None yet

2 participants