-
Notifications
You must be signed in to change notification settings - Fork 35
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
Optimize instance #with
#57
base: master
Are you sure you want to change the base?
Conversation
Hi @tcrayford -- hope you get to look at this one as well -- assuming #56 is merged, this increases |
Codecov Report
@@ Coverage Diff @@
## master #57 +/- ##
==========================================
+ Coverage 96.42% 96.87% +0.44%
==========================================
Files 1 1
Lines 84 96 +12
==========================================
+ Hits 81 93 +12
Misses 3 3
Continue to review full report at Codecov.
|
@tcrayford have you had a chance to look at this? |
This PR is inspired by tcrayford#56, and assumes that code will be merged, so uses it in the benchmarks here: https://gist.github.com/ms-ati/fa8002ef8a0ce00716e9aa6510d3d4d9 It is common in our code, as in any idiomatic code using value objects in loops or pipelines, to call `#with` many times, returning a new immutable object each time with 1 or more fields replaced with new values. The optimizations in this PR eliminate a number of extra Hash and Array instantiations that were occurring each time, in favor of iterating only over the constant `VALUE_ATTRS` array and doing key lookups in the given Hash parameter in the hot paths. Per the gist above, this increases ips (iterations per second) 2.29x, from 335.9 to 769.6 on my machine.
15c0489
to
c3f00e3
Compare
@tcrayford ping again |
@tcrayford Please note, we are having to depend on my branch here, that uses the merged PR #56 followed by this unmerged PR #57, for a very significant speed-up. Do you feel comfortable merging and making a release? Would you like to discuss any changes to this PR? |
@tcrayford ping again |
This PR is inspired by #56, and
assumes that code will be merged, so uses it in the benchmarks here:
https://gist.github.com/ms-ati/fa8002ef8a0ce00716e9aa6510d3d4d9
It is common in our code, as in any idiomatic code using value objects
in loops or pipelines, to call
#with
many times, returning a new immutableobject each time with 1 or more fields replaced with new values.
The optimizations in this PR eliminate a number of extra Hash and Array
instantiations that were occurring each time, in favor of iterating only over
the constant
VALUE_ATTRS
array and doing key lookups in the givenHash parameter in the hot paths.
Per the gist above, this increases ips (iterations per second) 2.29x, from
335.9 to 769.6 on my machine.
cc @michaeldiscala