⚡ [performance] Optimize Regexp Compilation in normalizeCommand - #45
⚡ [performance] Optimize Regexp Compilation in normalizeCommand#45eshanized wants to merge 1 commit into
Conversation
Co-authored-by: eshanized <148610067+eshanized@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. |
💡 What: Extract regex compilations into package-level variables in
internal/tools/exec/bash.gofor thenormalizeCommandfunction.🎯 Why: To eliminate repetitive dynamic regex recompilations on every invocation of
normalizeCommand, which was a major CPU overhead.📊 Measured Improvement: We built a benchmark to evaluate the time cost. The time taken dropped from
7303 ns/op(baseline) to3588 ns/op(optimized). This is an improvement of over 50%.PR created automatically by Jules for task 12628495636815695939 started by @eshanized
Summary by cubic
Precompiles the regexes used by
normalizeCommandininternal/tools/execto avoid per-call compilation and cut CPU time. Previously we compiled two patterns on every call; now we reuse package-levelregexpinstances. Behavior is unchanged.removeCommentsRegex,collapseSpaceRegex).regexpinstances are safe for concurrent reads.normalizeCommandare unchanged.Written for commit 7b344a5. Summary will update on new commits.