Skip to content

⚡ Bolt: [performance improvement] Pre-compile event routing patterns#155

Open
docxology wants to merge 5 commits intomainfrom
bolt-event-routing-perf-5518424385788024756
Open

⚡ Bolt: [performance improvement] Pre-compile event routing patterns#155
docxology wants to merge 5 commits intomainfrom
bolt-event-routing-perf-5518424385788024756

Conversation

@docxology
Copy link
Copy Markdown
Owner

💡 What:
Optimized the event routing hot path in both EventBus (event_bus.py) and IntegrationBus (integration_bus.py). Replaced fnmatch.fnmatch() evaluation per invocation with:

  1. Pre-compiling any wildcard patterns (*, ?, [) into native re.Pattern objects when a subscription is registered.
  2. Grouping literal, non-wildcard patterns into standard sets for fast O(1) string matching.

🎯 Why:
fnmatch.fnmatch() creates significant CPU overhead when used sequentially against hundreds of string patterns on every single event emitted over the bus. Given the central role the event bus plays in system throughput, this pattern matching was a major bottleneck under load.

📊 Impact:

  • Significantly reduces the CPU time taken to route and dispatch an event.
  • Benchmark: 1000 topics evaluated against 1000 published events drops from ~1.58s to ~0.53s.

🔬 Measurement:

  • Start an application under load or run the associated unit tests with profiling enabled. You will see a severe drop in the amount of time spent inside string evaluation.
  • All unit tests covering wildcards, literal topics, and prioritizations continue to pass correctly.

PR created automatically by Jules for task 5518424385788024756 started by @docxology

This commit optimizes the routing hot path in both `EventBus` and `IntegrationBus` by replacing the use of `fnmatch.fnmatch()` per event emission with a mix of O(1) set lookups for exact string matches and pre-compiled regex `re.Pattern` matching for wildcard topics.

Impact:
This optimization heavily reduces the overhead associated with pub/sub event matching, saving multiple CPU cycles per event emission. Testing demonstrates event matching taking ~0.5s instead of ~1.5s (in isolated benchmarks with 1000 topics emitted 1000 times).

Co-authored-by: docxology <6911384+docxology@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.

@github-actions
Copy link
Copy Markdown

🤖 Hi @docxology, I've received your request, and I'm working on it now! You can track my progress in the logs for more details.

@github-actions
Copy link
Copy Markdown

🤖 Jules AI — Thanks for the contribution!

Automated Checklist:

  • CI checks pass
  • No merge conflicts
  • Changes follow zero-mock testing policy
  • Documentation updated if needed

This PR will be auto-labeled and auto-merged if all checks pass.

@github-actions
Copy link
Copy Markdown

🤖 I'm sorry @docxology, but I was unable to process your request. Please see the logs for more details.

google-labs-jules bot and others added 4 commits March 10, 2026 01:51
This commit optimizes the routing hot path in both `EventBus` and `IntegrationBus` by replacing the use of `fnmatch.fnmatch()` per event emission with a mix of O(1) set lookups for exact string matches and pre-compiled regex `re.Pattern` matching for wildcard topics.

Impact:
This optimization heavily reduces the overhead associated with pub/sub event matching, saving multiple CPU cycles per event emission. Testing demonstrates event matching taking ~0.5s instead of ~1.5s (in isolated benchmarks with 1000 topics emitted 1000 times).

Co-authored-by: docxology <6911384+docxology@users.noreply.github.com>
This commit optimizes the routing hot path in both `EventBus` and `IntegrationBus` by replacing the use of `fnmatch.fnmatch()` per event emission with a mix of O(1) set lookups for exact string matches and pre-compiled regex `re.Pattern` matching for wildcard topics.

Impact:
This optimization heavily reduces the overhead associated with pub/sub event matching, saving multiple CPU cycles per event emission. Testing demonstrates event matching taking ~0.5s instead of ~1.5s (in isolated benchmarks with 1000 topics emitted 1000 times).

Co-authored-by: docxology <6911384+docxology@users.noreply.github.com>
This commit optimizes the routing hot path in both `EventBus` and `IntegrationBus` by replacing the use of `fnmatch.fnmatch()` per event emission with a mix of O(1) set lookups for exact string matches and pre-compiled regex `re.Pattern` matching for wildcard topics.

Impact:
This optimization heavily reduces the overhead associated with pub/sub event matching, saving multiple CPU cycles per event emission. Testing demonstrates event matching taking ~0.5s instead of ~1.5s (in isolated benchmarks with 1000 topics emitted 1000 times).

Co-authored-by: docxology <6911384+docxology@users.noreply.github.com>
This commit optimizes the routing hot path in both `EventBus` and `IntegrationBus` by replacing the use of `fnmatch.fnmatch()` per event emission with a mix of O(1) set lookups for exact string matches and pre-compiled regex `re.Pattern` matching for wildcard topics.

Impact:
This optimization heavily reduces the overhead associated with pub/sub event matching, saving multiple CPU cycles per event emission. Testing demonstrates event matching taking ~0.5s instead of ~1.5s (in isolated benchmarks with 1000 topics emitted 1000 times).

Co-authored-by: docxology <6911384+docxology@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