Skip to content

⚡ Bolt: Optimize search core by caching and hoisting loop invariants#1007

Merged
ImChong merged 1 commit into
mainfrom
bolt-search-invariant-hoisting-16150203814616876593
Jul 9, 2026
Merged

⚡ Bolt: Optimize search core by caching and hoisting loop invariants#1007
ImChong merged 1 commit into
mainfrom
bolt-search-invariant-hoisting-16150203814616876593

Conversation

@ImChong

@ImChong ImChong commented Jul 9, 2026

Copy link
Copy Markdown
Owner

💡 What:
In scripts/search_wiki_core.py, I pre-computed and cached properties like page_type_l, page_tags_l, status_boost, and path_l on the static doc instances during the initial for doc in docs: parsing pass. Additionally, I hoisted the dynamic evaluation of query_joined = " ".join(query_tokens).lower() out of the hot document processing loop.

🎯 Why:
Previously, the search() loop evaluated these properties recursively by extracting properties from dictionaries and applying intensive string operations (e.g. .lower(), .replace("\\", "/")) or floating-point status multipliers on every doc in docs for every search. Computing loop-invariant values inside a hot loop scales execution overhead exponentially as the document collection grows.

📊 Impact:
By caching the transformed strings and constants onto the doc object directly, the inner-most scoring and filtering helper functions (_filter_doc, _canonical_topic_boost, _sim2real_intent_boost, _query_has_comparison_intent) avoid redundant string allocations, .lower() conversions, and mathematical scalar recalcs completely. This significantly reduces GC thrashing and improves search processing latency per request.

🔬 Measurement:

  • Run make test to ensure existing regression queries return exact matching items.
  • Run make ci-preflight to ensure no search evaluations degrade.

PR created automatically by Jules for task 16150203814616876593 started by @ImChong

Co-authored-by: ImChong <74563097+ImChong@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.

@ImChong ImChong merged commit 35e8187 into main Jul 9, 2026
7 checks passed
@ImChong ImChong deleted the bolt-search-invariant-hoisting-16150203814616876593 branch July 9, 2026 15:54
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