Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds the following optimizations: partial instrumentation and avoiding array boxing.
Partial instrumentation
Instrument after/before only if the handler defines hooks for them. I did this trying to stay backwards compatible as much as possible.
This is implemented by adding specialized trap methods with more or less instrumentation, and selecting the trap method depending on the methods redefined by the handler. The downside of the approach is that the trap method is defined at proxy installation time, and if the handler changes in between adding new hooks (very unlikely), the trap will not take that into account.
Avoid array boxing
Method arguments as passed as normal individual arguments instead of boxing them into an array.
I extended the handler API to manage methods from 0 to 5 arguments in this way.
Methods with more than 5 arguments are still using the array boxing convention.
Benchmarks
I did four benches,
on:
fibonachi (0 args, highly recursive)
20 benchFib."Baseline -- no instrumentation"
"88,067 iterations in 5 seconds 3 milliseconds. 17602.838 per second"
max: (1 arg)
1 max: 17"Baseline -- no instrumentation"
"982,709,414 iterations in 5 seconds 4 milliseconds. 196384774.980 per second"
Base code:
Fibonacci, empty instumentation
9069 / 7643 = ~1.19x improvement
Fibonacci, counting
11489 / 7439 = 1.54x speedup.
max:empty instrumentation"Not optimized"
bench. "187,399,224 iterations in 5 seconds 3 milliseconds. 37457370.378 per second"
"Optimized"
bench "208,645,555 iterations in 5 seconds 2 milliseconds. 41712426.030 per second"
208645555 / 187399224 = 1.11x speedup
max:, counting266138612 / 167488782 = 1.58x speedup.