⚡ Bolt: [performance improvement] Pre-compile regexes and cache static lists in keyword_density#314
Conversation
Moves inline compiled regexes and list/set allocations in `cli/utils/keyword_density.py` to module-level constants (`_TITLE_PATTERNS`, `_COMPANY_PATTERNS`, `_COMMON_KEYWORDS`, `_TECH_KEYWORDS`) to prevent overhead on every function call. Includes converting `_TECH_KEYWORDS` from a list to a set for O(1) lookups. Co-authored-by: anchapin <6326294+anchapin@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. |
Reviewer's GuidePre-compiles regex patterns and hoists static keyword collections in keyword_density to module-level constants, switching tech keyword lookups to a set for faster membership checks, and documents the performance pattern in the Bolt notes. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider deriving
_TECH_KEYWORDSprogrammatically from_COMMON_KEYWORDS(or documenting why it intentionally diverges), so future changes to one list don’t silently fall out of sync with the other. - Since these pre-compiled regexes and keyword collections are effectively constants, you might standardize the naming convention (e.g., either drop the leading underscore or add a short comment about them being private module-level constants) to make their intended usage and visibility clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider deriving `_TECH_KEYWORDS` programmatically from `_COMMON_KEYWORDS` (or documenting why it intentionally diverges), so future changes to one list don’t silently fall out of sync with the other.
- Since these pre-compiled regexes and keyword collections are effectively constants, you might standardize the naming convention (e.g., either drop the leading underscore or add a short comment about them being private module-level constants) to make their intended usage and visibility clearer.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
💡 What: Extracted regex objects and statically defined lists from inside functions (
_extract_job_details,_simple_keyword_extraction,_suggest_sections_for_keyword) into module-level constants.tech_keywordswas converted from a list to a set.🎯 Why: During text parsing and report generation, recreating arrays, compiling regexes, and doing linear scans through lists on each method call introduces an unnecessary overhead. The
KeywordDensityGeneratoranalyzes block text and these elements are static.📊 Impact: Reduces memory allocations and avoids repetitive regex compilation parsing during keyword extraction and density analysis. O(1) membership checking on
_TECH_KEYWORDS.🔬 Measurement: Verify changes in
cli/utils/keyword_density.py. Runmake format,make lintand thepython -m pytest tests/test_keyword_density.pytesting suite to ensure the text parsing and analysis remains identical.PR created automatically by Jules for task 6125094139170230434 started by @anchapin
Summary by Sourcery
Optimize keyword density analysis by hoisting regex patterns and keyword collections to module-level constants and updating internal documentation with the new performance learnings.
Enhancements:
Documentation: