-
Notifications
You must be signed in to change notification settings - Fork 947
Read Many Followups #25669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Read Many Followups #25669
Conversation
… tvaron3/readManyFollowups
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements two performance optimizations to the runEngineRequests function based on code review feedback:
-
Lock-free charge tracking: Replaces mutex-protected charge accumulation with per-worker array slots, eliminating lock contention when workers record request charges.
-
Batched result delivery: Changes from calling
ProvideDatafor each individual result to collecting all results and callingProvideDataonce with a single batch, reducing CGo overhead.
Key Changes
- Removed the provider goroutine and
chargeMumutex - Added per-worker
chargesarray indexed by worker ID for lock-free charge accumulation - Introduced a collector goroutine that gathers all
QueryResultitems intoallResults - Modified control flow to call
pipeline.ProvideDataonce after all workers complete - Changed function signature to use unnamed return values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Description
Following two changes from suggestions from @analogrelay to read many/ query apis,
Slight performance suggestion for a separate PR: Store request charges in an array with workerCount slots. Each worker can update the request charge slot using it's worker index w without a lock. Sum up all the slots at the end, when all the workers are done.
As a refactoring for later, we can actually just collect all the results and call ProvideData once with a single batch. That's what it's designed for. You're right that it shouldn't be called simultaneously, but calling it once with a batch of items will also reduce CGo overhead.