Skip to content

⚡ Bolt: [performance improvement] Memoize regex compilations in ConText lexicon - #44

Draft
zrt219 wants to merge 1 commit into
mainfrom
performance/memoize-regex-compilation-5828637516621425941
Draft

⚡ Bolt: [performance improvement] Memoize regex compilations in ConText lexicon#44
zrt219 wants to merge 1 commit into
mainfrom
performance/memoize-regex-compilation-5828637516621425941

Conversation

@zrt219

@zrt219 zrt219 commented Sep 1, 2026

Copy link
Copy Markdown
Owner

💡 What: Added memoization to _compiled_context_lexicon inside openmed/openmed/clinical/context.py using @functools.lru_cache(maxsize=None), and safely wrapped the dictionary returned by _cue_category_lookup into a types.MappingProxyType to 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_context overhead 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

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>
@vercel

vercel Bot commented Sep 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
zrt-bionemo Ready Ready Preview Sep 1, 2026 5:32pm UTC

@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.

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