From 93b82b2432b30a21f08810f247285119d2242475 Mon Sep 17 00:00:00 2001 From: Brian Morearty Date: Thu, 8 Mar 2018 19:22:31 -0800 Subject: [PATCH] Performance: memomize LinesClassifier::no_cov_line 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. --- CHANGELOG.md | 1 + lib/simplecov/lines_classifier.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 924bc11f..6ce3c420 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/simplecov/lines_classifier.rb b/lib/simplecov/lines_classifier.rb index 73130433..2bb4202d 100644 --- a/lib/simplecov/lines_classifier.rb +++ b/lib/simplecov/lines_classifier.rb @@ -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)