⚡ Optimize delta collector ignore check order#611
Conversation
Reordered the condition in `Coverband::Collectors::Delta#generate` and `#transform_oneshot_lines_results` to check `file.start_with?(@@project_directory)` before checking `@@ignore_patterns.none?`. This short-circuits expensive regex checks for files outside the project directory (e.g. gems), resulting in ~45% performance improvement in benchmarks. Co-authored-by: danmayer <24925+danmayer@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reordered the condition in `Coverband::Collectors::Delta#generate` and `#transform_oneshot_lines_results` to check `file.start_with?(@@project_directory)` before checking `@@ignore_patterns.none?`. Added `test/benchmarks/benchmark_delta.rb` to verify performance improvements. This short-circuits expensive regex checks for files outside the project directory (e.g. gems), resulting in ~45% performance improvement in benchmarks. Co-authored-by: danmayer <24925+danmayer@users.noreply.github.com>
💡 What:
Reordered the condition in
Coverband::Collectors::Delta#generateand#transform_oneshot_lines_resultsto checkfile.start_with?(@@project_directory)before checking@@ignore_patterns.none?.🎯 Why:
Checking if a file starts with the project directory is a fast string operation. Checking if a file matches any of the ignore patterns involves iterating over regexes, which is much more expensive.
By swapping the order, we short-circuit the expensive regex check for any file that is not in the project directory (e.g., gems, standard library files), which are commonly present in coverage data but irrelevant for the report.
📊 Measured Improvement:
Benchmark
test/benchmarks/benchmark_delta.rb(10,000 files, mixed project/non-project/ignored) shows significant improvement:Baseline: ~28.6 i/s
Optimized: ~41.5 i/s
Improvement: ~45% speedup in the Delta generation loop.
PR created automatically by Jules for task 13182039091391808887 started by @danmayer