⚡ Bolt: [performance improvement] Memoize regex compilations in ConText lexicon - #44
⚡ Bolt: [performance improvement] Memoize regex compilations in ConText lexicon#44zrt219 wants to merge 1 commit into
Conversation
Optimizes the `_compiled_context_lexicon` function in `openmed.clinical.context` by wrapping it with `@functools.lru_cache(maxsize=None)` and ensuring immutability with `types.MappingProxyType`. This prevents compiling identical and complex regex patterns multiple times across different span resolutions, significantly improving performance for heavy clinical document evaluation pipelines. Co-authored-by: zrt219 <199104500+zrt219@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
👋 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: Added memoization to
_compiled_context_lexiconinsideopenmed/openmed/clinical/context.pyusing@functools.lru_cache(maxsize=None), and safely wrapped the dictionary returned by_cue_category_lookupinto atypes.MappingProxyTypeto prevent downstream mutation errors. Added a journal entry to.jules/bolt.md.🎯 Why: The function repeatedly parses arrays of text cues and dynamically builds complex regex patterns without any caching. This function is called extensively within the context resolution lifecycle (e.g.
resolve_temporality,resolve_uncertainty, etc).📊 Impact: Massively reduces overhead by skipping regex rebuilds. Speeds up clinical text extraction by eliminating constant
re.compile()calls for every cue check.🔬 Measurement: Benchmark
resolve_span_contextoverhead or run end-to-end integration tests over large documents, which should see a drastic CPU usage reduction in pattern compiling functions.PR created automatically by Jules for task 5828637516621425941 started by @zrt219