⚡ Bolt: Optimize search core by caching and hoisting loop invariants#1007
Conversation
Co-authored-by: ImChong <74563097+ImChong@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:
In
scripts/search_wiki_core.py, I pre-computed and cached properties likepage_type_l,page_tags_l,status_boost, andpath_lon the staticdocinstances during the initialfor doc in docs:parsing pass. Additionally, I hoisted the dynamic evaluation ofquery_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 everydocindocsfor 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
docobject 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:
make testto ensure existing regression queries return exact matching items.make ci-preflightto ensure no search evaluations degrade.PR created automatically by Jules for task 16150203814616876593 started by @ImChong