Conversation
Optimized `LATIN_REGEX` in `evolutia/utils/math_extractor.py` by consolidating vector patterns (`\vec`, `\mathbf`, `\hat`) into a single non-capturing group.
This reduces the number of alternation branches and capturing groups for the regex engine, resulting in a ~12-32% speedup in variable extraction benchmarks.
- Replaced `\vec{...}|\mathbf{...}|\hat{...}` with `(?:\vec|mathbf|hat){...}`
- Reduced capture groups from 4 to 2 in `LATIN_REGEX`.
- Verified correctness with `tests/test_math_extractor.py`.
- No semantic information loss as `extract_variables` only extracts variable names.
Co-authored-by: glacy <1131951+glacy@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. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the regular expression pattern used for extracting mathematical variables in LaTeX expressions. The optimization reduces regex complexity by consolidating three separate capturing groups into a single non-capturing group with alternatives, improving performance by reducing backtracking and capture group overhead.
Changes:
- Refactored
LATIN_REGEXpattern to use non-capturing groups(?:vec|mathbf|hat)instead of three separate alternations with individual capturing groups, reducing the number of capture groups from 4 to 2
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Patrones comunes para variables | ||
| # Variables latinas: \vec{A}, A, \mathbf{B}, etc. | ||
| LATIN_REGEX = r'\\vec\{([A-Za-z])\}|\\mathbf\{([A-Za-z])\}|\\hat\{([A-Za-z])\}|([A-Za-z])(?![a-z])' | ||
| # Optimized: use non-capturing group for vector types to reduce branches |
There was a problem hiding this comment.
This comment should be in Spanish to follow the codebase convention. Most comments in this file are in Spanish (e.g., lines 10, 11, 15, 21). Consider changing to: "# Optimizado: usa grupo no capturador para tipos de vector para reducir ramificaciones"
| # Optimized: use non-capturing group for vector types to reduce branches | |
| # Optimizado: usa grupo no capturador para tipos de vector para reducir ramificaciones |
Optimized regex for variable extraction in
math_extractor.pyto improve performance by reducing backtracking and group overhead.PR created automatically by Jules for task 8890657918661583580 started by @glacy