Repository navigation
Conversation
Contributor
Author
|
👋 @amatsuda Do you mind reviewing this optimization? |
Prior this change `Integer#to_i` and `NilClass#to_i` showed up in stack profiler which resulted to slow down `merge_line_coverage` a lot. This change brought down the run time from 1m28s to 1m18s on a large resultset (GitLab).
Create less intermediate objects.
splattael
force-pushed
the
optimize-merge_line_coverage
branch
from
July 1, 2025 11:47
bc059fc to
08cac5a
Compare
Contributor
Author
Contributor
Author
|
I've tested diff --git a/lib/simplecov/combine/lines_combiner.rb b/lib/simplecov/combine/lines_combiner.rb
index cddffa5..97a21cc 100644
--- a/lib/simplecov/combine/lines_combiner.rb
+++ b/lib/simplecov/combine/lines_combiner.rb
@@ -32,12 +32,12 @@ module SimpleCov
#
# @return [Integer || nil]
def merge_line_coverage(first_val, second_val)
- sum = first_val.to_i + second_val.to_i
-
- if sum.zero? && (first_val.nil? || second_val.nil?)
- nil
- else
- sum
+ if first_val && second_val
+ first_val + second_val
+ elsif first_val
+ first_val.zero? ? nil : first_val
+ elsif second_val
+ second_val.zero? ? nil : second_val
end
end
endand it improved performance even more: 9s -> 6.8s. |
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 optimizes merging line coverage:
Integer#to_iandNilClass#to_ishowed up in stack profiler which resulted to slow downmerge_line_coveragea lotArray#zipcreated a lot of intermediate objectsThese changes brought down the run time from 1m28s to 1m8s on a large resultset (GitLab).
Stack profile
Before
After