Skip to content

⚡ [performance] Optimize get_thread_detail item fetching (N+1 fix)#3141

Closed
Hmbown wants to merge 1 commit into
mainfrom
fix-n-plus-1-thread-detail-17939346021233864145
Closed

⚡ [performance] Optimize get_thread_detail item fetching (N+1 fix)#3141
Hmbown wants to merge 1 commit into
mainfrom
fix-n-plus-1-thread-detail-17939346021233864145

Conversation

@Hmbown

@Hmbown Hmbown commented Jun 12, 2026

Copy link
Copy Markdown
Owner

💡 What: Added list_items_for_turns_map to RuntimeThreadStore to scan the items directory once and group items by their associated turn_id. Then modified get_thread_detail to utilize this batch fetch instead of reading the directory per turn.
🎯 Why: get_thread_detail iterates over all turns, calling list_items_for_turn for each. Since list_items_for_turn performs an fs::read_dir on the items_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_detail decreased from ~2.06 seconds to ~26.5 milliseconds, an ~80x improvement.


PR created automatically by Jules for task 17939346021233864145 started by @Hmbown

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

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@Hmbown Hmbown added this to the v0.8.65 milestone Jun 13, 2026
@github-actions

Copy link
Copy Markdown

Thanks @Hmbown — your contribution landed in 119285f0565c on main:

fix(runtime): batch thread detail item reads

Closing this PR now that the code is on main. Credit lives in the commit message and (where applicable) the CHANGELOG.md entry for the next release. Apologies for not closing this at the time of the merge — the auto-close workflow is new in v0.8.31.

If you want to land more work and would prefer your future PRs merge cleanly without a harvest step, the CONTRIBUTING.md doc has a short note on what makes a contribution mergeable as-is.

@github-actions github-actions Bot closed this Jun 14, 2026
pull Bot pushed a commit to dolfly/DeepSeek-TUI that referenced this pull request Jun 14, 2026
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>
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