Skip to content

Commit

Permalink
Performance: memomize LinesClassifier::no_cov_line
Browse files Browse the repository at this point in the history
In my measurements the majority of the time in SimpleCov was being
spent in this one-line function.

In my tests on a large project, this change makes SimpleCov run
from 2.5x to 3.75x faster.

Admittedly, memoizing it does change its behavior but only in the edge
case where someone runs SimpleCov twice in a single test run, changing
the +nocov_token+ between the two runs. This is such an odd edge case I
decided not to worry about it.
  • Loading branch information
BMorearty committed Mar 9, 2018
1 parent 5cf19c6 commit 93b82b2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ unreleased

* Relax version constraint on `docile`, per SemVer
* exception that occurred on exit is available as `exit_exception`! See [#639](https://github.com/colszowka/simplecov/pull/639) (thanks @thomas07vt)
* Performance: processing results now runs from 2.5x to 3.75x faster.

## Bugfixes

Expand Down
2 changes: 1 addition & 1 deletion lib/simplecov/lines_classifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LinesClassifier
WHITESPACE_OR_COMMENT_LINE = Regexp.union(WHITESPACE_LINE, COMMENT_LINE)

def self.no_cov_line
/^(\s*)#(\s*)(\:#{SimpleCov.nocov_token}\:)/
@no_cov_line ||= /^(\s*)#(\s*)(\:#{SimpleCov.nocov_token}\:)/
end

def classify(lines)
Expand Down

0 comments on commit 93b82b2

Please sign in to comment.