⚡ [performance] Optimize get_thread_detail item fetching (N+1 fix)#3141
⚡ [performance] Optimize get_thread_detail item fetching (N+1 fix)#3141Hmbown wants to merge 1 commit into
Conversation
Resolved an N+1 query issue in `RuntimeThreadStore::get_thread_detail` that significantly impacted performance when reading many turns. Added a `list_items_for_turns_map` method that scans the filesystem only once instead of looping through each turn. Performance improved from ~2.06s to ~26.5ms for a test thread containing 100 turns and 1,000 items. Co-authored-by: Hmbown <101357273+Hmbown@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. |
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Thanks @Hmbown — your contribution landed in
Closing this PR now that the code is on If you want to land more work and would prefer your future PRs merge cleanly without a harvest step, the |
Avoid an N+1 item-directory scan when loading runtime thread details by grouping persisted items for all turns in one pass. Harvested from PR Hmbown#3141. Co-authored-by: Hmbown <101357273+Hmbown@users.noreply.github.com> Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
💡 What: Added
list_items_for_turns_maptoRuntimeThreadStoreto scan theitemsdirectory once and group items by their associatedturn_id. Then modifiedget_thread_detailto utilize this batch fetch instead of reading the directory per turn.🎯 Why:
get_thread_detailiterates over all turns, callinglist_items_for_turnfor each. Sincelist_items_for_turnperforms anfs::read_diron theitems_dir, doing this inside the loop results in an N+1 filesystem scan.📊 Measured Improvement: Created a targeted benchmark testing 100 turns, each with 10 items (1,000 total items). The time to fetch
get_thread_detaildecreased from ~2.06 seconds to ~26.5 milliseconds, an ~80x improvement.PR created automatically by Jules for task 17939346021233864145 started by @Hmbown