-
Notifications
You must be signed in to change notification settings - Fork 63
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
Performance and memory fixes #52
Merged
liufengyun
merged 7 commits into
liufengyun:master
from
krzysiek1507:feature/performance-fixes
Apr 22, 2019
Merged
Performance and memory fixes #52
liufengyun
merged 7 commits into
liufengyun:master
from
krzysiek1507:feature/performance-fixes
Apr 22, 2019
Conversation
This file contains 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
krzysiek1507
force-pushed
the
feature/performance-fixes
branch
from
April 18, 2019 18:07
eccae36
to
c55d171
Compare
lib/hashdiff/util.rb:11:20: C: Use (count_a + count_b).zero? instead of count_a + count_b == 0.
return true if count_a + count_b == 0
^^^^^^^^^^^^^^^^^^^^^^ In fact |
krzysiek1507
force-pushed
the
feature/performance-fixes
branch
from
April 18, 2019 18:20
25e61ad
to
bdab797
Compare
If it is easier to review, I can split it into smaller PRs. |
Thanks @krzysiek1507 -- One PR is fine. I'm wondering why some test failed, could you have a look? |
It's rubocop and this particular rule doesn't make sense in this case. lib/hashdiff/util.rb:85:5: C: Style/IfUnlessModifier: Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
if options[:numeric_tolerance].is_a?(Numeric) && obj1.is_a?(Numeric) && obj2.is_a?(Numeric)
^^ |
when both objects are empty hashes or arrays: Warming up -------------------------------------- original 18.539k i/100ms optimized 120.971k i/100ms Calculating ------------------------------------- original 204.282k (± 2.1%) i/s - 1.038M in 5.084371s optimized 1.968M (± 3.1%) i/s - 9.920M in 5.046494s Comparison: optimized: 1967768.6 i/s original: 204281.6 i/s - 9.63x slower Calculating ------------------------------------- original 1.568k memsize ( 0.000 retained) 20.000 objects ( 0.000 retained) 2.000 strings ( 0.000 retained) optimized 232.000 memsize ( 0.000 retained) 1.000 objects ( 0.000 retained) 0.000 strings ( 0.000 retained) Comparison: optimized: 232 allocated original: 1568 allocated - 6.76x more
krzysiek1507
force-pushed
the
feature/performance-fixes
branch
from
April 18, 2019 19:10
bdab797
to
e106ef2
Compare
Some stats: obj1 = obj2 = []
Warming up --------------------------------------
master 49.253k i/100ms
Calculating -------------------------------------
master 590.795k (± 2.1%) i/s - 2.955M in 5.004451s
Calculating -------------------------------------
master 856.000 memsize ( 0.000 retained)
7.000 objects ( 0.000 retained)
0.000 strings ( 0.000 retained)
Warming up --------------------------------------
optimized 82.442k i/100ms
Calculating -------------------------------------
optimized 1.140M (± 1.8%) i/s - 5.771M in 5.061820s
Calculating -------------------------------------
optimized 544.000 memsize ( 0.000 retained)
4.000 objects ( 0.000 retained)
0.000 strings ( 0.000 retained)
================================================
obj1 = obj2 = {}
Warming up --------------------------------------
master 24.736k i/100ms
Calculating -------------------------------------
master 274.993k (± 5.6%) i/s - 1.385M in 5.059656s
Calculating -------------------------------------
master 1.024k memsize ( 0.000 retained)
16.000 objects ( 0.000 retained)
0.000 strings ( 0.000 retained)
Warming up --------------------------------------
optimized 25.828k i/100ms
Calculating -------------------------------------
optimized 314.045k (± 5.0%) i/s - 1.576M in 5.032663s
Calculating -------------------------------------
optimized 824.000 memsize ( 0.000 retained)
11.000 objects ( 0.000 retained)
0.000 strings ( 0.000 retained)
================================================
obj1 = { a: 1, b: { b2: [], b3: [{ b4: 1 }] }, h: [1, 2, 3, 4, 5], i: 2, j: 2, k: [] }
obj2 = { a: 1, b: { b2: [], b3: [{ b4: 1 }] }, g: [1, 2, 3, 4, 5], i: 2, j: 4, k: {} }
Warming up --------------------------------------
master 1.540k i/100ms
Calculating -------------------------------------
master 15.653k (± 8.4%) i/s - 78.540k in 5.072408s
Calculating -------------------------------------
master 14.608k memsize ( 0.000 retained)
164.000 objects ( 0.000 retained)
17.000 strings ( 0.000 retained)
Warming up --------------------------------------
optimized 1.789k i/100ms
Calculating -------------------------------------
optimized 18.383k (± 2.6%) i/s - 93.028k in 5.063884s
Calculating -------------------------------------
optimized 12.592k memsize ( 0.000 retained)
128.000 objects ( 0.000 retained)
17.000 strings ( 0.000 retained) |
Thanks @krzysiek1507. Maybe we can silence rubocop in that case? |
obj1 = 1, obj2 = 1.1, numeric_tolerance = 0.1 Warming up -------------------------------------- original 106.128k i/100ms optimized 161.873k i/100ms Calculating ------------------------------------- original 1.682M (± 5.8%) i/s - 8.384M in 5.005149s optimized 3.560M (± 2.4%) i/s - 17.806M in 5.005019s Comparison: optimized: 3559889.7 i/s original: 1682449.9 i/s - 2.12x slower Calculating ------------------------------------- original 40.000 memsize ( 0.000 retained) 1.000 objects ( 0.000 retained) 0.000 strings ( 0.000 retained) optimized 0.000 memsize ( 0.000 retained) 0.000 objects ( 0.000 retained) 0.000 strings ( 0.000 retained) Comparison: optimized: 0 allocated original: 40 allocated - Infx more
krzysiek1507
force-pushed
the
feature/performance-fixes
branch
from
April 22, 2019 16:47
e106ef2
to
6d028a6
Compare
@liufengyun done! |
Thanks a lot @krzysiek1507 🎉 |
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.
It should be a little bit faster (or a lot faster in some cases) and use less memory.