pat: remove allocation in match.Value(internal.Path) case #68
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.
hi @zenazn!
In an application I was benchmarking, about 40% of allocations per API request were from
match.Value
returning a string, and that return implicitly moving the string onto the heap for reference as aninterface{}
( https://github.com/golang/go/blob/master/src/runtime/iface.go#L388-L396 ). I plan to separately deal with that inefficient call pattern, but it will be more involved, and removing this allocation is relatively straight forward.I attempted a separate approach of trying to "just" use
context.WithValue
instead ofmatch
, but as you might have guessed that turned out to be ... not really workable ( https://github.com/goji/goji/compare/master...bpowers:goji:use-vanilla-ctx?expand=1 for reference).I think the biggest thing would be a double-check on my assumption that matches are immutable, so taking a reference to an entry in the slice is safe.
I'd also be happy to rebase this on the
v3
branch if thats more palatable!