Skip to content
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

reduces chunking allocations for wide relations #1751

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

vroldanbet
Copy link
Contributor

For most situations, when the number of elements to dispatch is below the default 100 elements, the slice with elements to dispatch was appropriately pre-allocated.

However, when dispatching large number of elements, the silence will grow from 1 up to the number of chunks, causing wasteful allocations in the critical path.

To simplify the logic, +1 is added to account for the situation the number of elements is less than the chunk size. For values above that it will cause one excess slice entry allocation, but seems like a reasonable tradeoff w.r.t extra annoying code to handle it.

@vroldanbet vroldanbet requested a review from a team as a code owner February 21, 2024 09:41
@vroldanbet vroldanbet self-assigned this Feb 21, 2024
@vroldanbet vroldanbet force-pushed the reduce-allocations-for-wide-relations branch from 6c0b580 to 31defe5 Compare February 21, 2024 09:42
@jzelinskie jzelinskie added area/perf Affects performance or scalability area/dispatch Affects dispatching of requests labels Feb 21, 2024
@vroldanbet vroldanbet force-pushed the reduce-allocations-for-wide-relations branch from 31defe5 to 193c618 Compare February 23, 2024 17:22
@vroldanbet vroldanbet requested review from jzelinskie and removed request for josephschorr February 23, 2024 17:22
@github-actions github-actions bot removed the area/dispatch Affects dispatching of requests label Feb 23, 2024
@@ -383,7 +383,10 @@ func (cc *ConcurrentChecker) checkDirect(ctx context.Context, crc currentRequest
it.Close()

// Convert the subjects into batched requests.
toDispatch := make([]directDispatch, 0, subjectsToDispatch.Len())
// To simplify the logic, +1 is added to account for the situation
Copy link
Member

Choose a reason for hiding this comment

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

situation where

@@ -601,7 +604,10 @@ func (cc *ConcurrentChecker) checkTupleToUserset(ctx context.Context, crc curren
it.Close()

// Convert the subjects into batched requests.
toDispatch := make([]directDispatch, 0, subjectsToDispatch.Len())
// To simplify the logic, +1 is added to account for the situation
Copy link
Member

Choose a reason for hiding this comment

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

ditto

For most situations, when the number of elements to dispatch
is below the default 100 elements, the slice with elements
to dispatch was appropriately pre-allocated.

However, when dispatching large number of elements, the
silence will grow from 1 up to the number of chunks, causing
wasteful allocations in the critical path.

To simplify the logic, +1 is added to account for the situation
the number of elements is less than the chunk size. For values
above that it will cause one excess slice entry allocation, but seems
like a reasonable tradeoff w.r.t extra annoying code to handle it.
@vroldanbet vroldanbet force-pushed the reduce-allocations-for-wide-relations branch from 193c618 to 1d46c13 Compare February 23, 2024 19:01
Copy link
Member

@josephschorr josephschorr left a comment

Choose a reason for hiding this comment

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

LGTM

@vroldanbet vroldanbet added this pull request to the merge queue Feb 23, 2024
Merged via the queue into main with commit ba2547f Feb 23, 2024
20 checks passed
@vroldanbet vroldanbet deleted the reduce-allocations-for-wide-relations branch February 23, 2024 19:29
@github-actions github-actions bot locked and limited conversation to collaborators Feb 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/perf Affects performance or scalability
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants