Micro optimization: avoid recompiling regex in incremental_coverage.py#7953
Micro optimization: avoid recompiling regex in incremental_coverage.py#7953mhucka wants to merge 2 commits intoquantumlib:mainfrom
incremental_coverage.py#7953Conversation
Compiling regex inside a function that is potentially called multiple times adds unnecessary overhead.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7953 +/- ##
==========================================
- Coverage 99.63% 99.62% -0.01%
==========================================
Files 1108 1108
Lines 99571 99574 +3
==========================================
- Hits 99205 99204 -1
- Misses 366 370 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
pavoljuhas
left a comment
There was a problem hiding this comment.
After adding a blank line to every Python source in this repo, the wall time before and with this PR for
python dev_tools/check_incremental_coverage_annotations.py origin/main
changed from 9.1 to 8.9 s. This should be considered in context of a preceding pytest coverage run needed to create .cover files which takes about 5 minutes. The improvement in time is at this scale negligible; indeed re.search caches its compiled patterns so any difference is likely from cache lookup overhead.
The other possible benefit of this PR could be in making the code more readable, but it goes the opposite way by adding more module constants. The level of improvement here does not justify more work.
The function
determine_ignored_lines()indev_tools/incremental_coverage.pycompiled a regex. Compiling regex inside a function that is potentially called multiple times adds unnecessary overhead. This PR pre-compiles some regex patterns at the module level indev_tools/incremental_coverage.pyto avoid redundant compilation.In simple wall-clock timings on a linux VM, running
dev_tools/pytest-and-incremental-coverage, I get an average of about 10% time improvement over the unmodified version of the file.(Full disclosure: this was largely the work of Jules, which I've experimenting with.)