Skip to content

⚡ Bolt: Precompile regex in job parser#232

Open
anchapin wants to merge 2 commits intomainfrom
bolt-optimize-regex-15321808004618941537
Open

⚡ Bolt: Precompile regex in job parser#232
anchapin wants to merge 2 commits intomainfrom
bolt-optimize-regex-15321808004618941537

Conversation

@anchapin
Copy link
Copy Markdown
Owner

@anchapin anchapin commented Apr 5, 2026

This pull request introduces a micro-optimization to the JobParser by compiling frequently used regex patterns at the module level.

💡 What:
The regex patterns used in _extract_salary_from_text, _extract_job_type, and _extract_experience_level were previously defined as lists of strings and evaluated using re.search inside a loop on every method call. These have been hoisted to module-level constants _SALARY_PATTERNS, _JOB_TYPE_PATTERNS, and _EXPERIENCE_LEVEL_PATTERNS using re.compile.

🎯 Why:
Compiling regex patterns and moving list allocations outside the method body removes overhead from the hot path during job parsing, ensuring we don't repeatedly parse and compile the same strings.

📊 Impact:
Measurably faster execution time for parsing job descriptions by avoiding redundant compilation overhead.

🔬 Measurement:
Run the existing test suite (python3 -m pytest tests/test_job_parser_integration.py) to verify behavior correctness. Performance impact can be measured when executing bulk parsing tasks on large HTML sets.


PR created automatically by Jules for task 15321808004618941537 started by @anchapin

Summary by Sourcery

Enhancements:

  • Hoist salary, job type, and experience level regex patterns to module-level compiled constants to avoid repeated compilation within extraction helpers.

What: Hoisted and pre-compiled regex patterns for salary, job type, and experience level extraction at the module level.
Why: Reduces regex compilation overhead and list allocation on every method invocation when parsing job descriptions.
Impact: Faster job parsing throughput, especially when processing large or multiple job descriptions.

Co-authored-by: anchapin <6326294+anchapin@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 5, 2026

Reviewer's Guide

Precompiles regex patterns for salary, job type, and experience level extraction in JobParser at the module level and updates the extraction methods to use these compiled patterns instead of re-searching over raw pattern strings on each call.

Class diagram for JobParser regex precompilation changes

classDiagram
    class JobParserModule {
        <<module>>
        +list _SALARY_PATTERNS
        +list _JOB_TYPE_PATTERNS
        +list _EXPERIENCE_LEVEL_PATTERNS
    }

    class JobParser {
        +_extract_salary_from_text(text str) Optional_str
        +_extract_job_type(html str) Optional_str
        +_extract_experience_level(html str) Optional_str
    }

    JobParserModule "1" o-- "*" JobParser : uses_compiled_patterns

    class RegexPattern {
        <<re_pattern>>
        +search(text str) Match_or_None
    }

    JobParserModule "*" o-- "*" RegexPattern : contains
    JobParser "3" --> "*" RegexPattern : calls_search_on
Loading

File-Level Changes

Change Details Files
Precompile salary extraction regex patterns at module scope and update salary extraction to use compiled patterns.
  • Introduce _SALARY_PATTERNS list of compiled regex objects for common salary formats using re.compile with IGNORECASE at module level.
  • Refactor _extract_salary_from_text to iterate over _SALARY_PATTERNS instead of constructing a local list of pattern strings on each call.
  • Switch from re.search with a pattern string and flags to calling pattern.search(text) on the compiled regex objects while preserving the existing group handling and cleanup logic.
cli/integrations/job_parser.py
Precompile job type regex patterns and refactor job type extraction to use them.
  • Add _JOB_TYPE_PATTERNS list of compiled regexes at module level to capture common job type terms.
  • Update _extract_job_type to loop over _JOB_TYPE_PATTERNS and call pattern.search(html) instead of re.search with inline pattern strings and flags.
cli/integrations/job_parser.py
Precompile experience level regex patterns and refactor experience level extraction to use them.
  • Add _EXPERIENCE_LEVEL_PATTERNS list of compiled regexes at module level to capture common experience level terms.
  • Update _extract_experience_level to loop over _EXPERIENCE_LEVEL_PATTERNS and call pattern.search(html) instead of re.search with inline pattern strings and flags.
cli/integrations/job_parser.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

What: Hoisted and pre-compiled regex patterns for salary, job type, and experience level extraction at the module level. Ensured the code is correctly formatted with black targeting Python 3.10.
Why: Reduces regex compilation overhead and list allocation on every method invocation when parsing job descriptions, while fixing the CI lint check failure.
Impact: Faster job parsing throughput, especially when processing large or multiple job descriptions.

Co-authored-by: anchapin <6326294+anchapin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant