⚡ Optimize entity detection with regex caching and pre-compilation - #828
Conversation
- Use functools.lru_cache to cache compiled patterns for entity names. - Pre-compile static pronoun patterns into a single regex. - Remove redundant .lower() calls in score_entity loop. Co-authored-by: igorls <4753812+igorls@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:
@functools.lru_cacheto_build_patternsto avoid redundant regex compilation for the same entity names.PRONOUN_PATTERNSinto a single pre-compiledPRONOUN_REregex.score_entityto usePRONOUN_RE.search()and eliminated a redundant.lower()call in the inner loop.🎯 Why:
Regex compilation is an expensive operation. In the original code,
score_entitywould trigger the compilation of multiple regexes every time it was called, even for previously processed entities. Additionally, the pronoun proximity check was looping over multiple patterns and performing redundant string operations.📊 Measured Improvement:
PR created automatically by Jules for task 3001788084232137906 started by @igorls