Reduce allocations in per-request methods to improve performance #395
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.