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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/graph/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 where
// the number of elements is less than the chunk size, and spare us some annoying code.
expectedNumberOfChunks := subjectsToDispatch.ValueLen()/int(crc.maxDispatchCount) + 1
vroldanbet marked this conversation as resolved.
Show resolved Hide resolved
toDispatch := make([]directDispatch, 0, expectedNumberOfChunks)
subjectsToDispatch.ForEachType(func(rr *core.RelationReference, resourceIds []string) {
chunkCount := 0.0
slicez.ForEachChunk(resourceIds, crc.maxDispatchCount, func(resourceIdChunk []string) {
Expand Down Expand Up @@ -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 where
// the number of elements is less than the chunk size, and spare us some annoying code.
expectedNumberOfChunks := subjectsToDispatch.ValueLen()/int(crc.maxDispatchCount) + 1
toDispatch := make([]directDispatch, 0, expectedNumberOfChunks)
subjectsToDispatch.ForEachType(func(rr *core.RelationReference, resourceIds []string) {
chunkCount := 0.0
slicez.ForEachChunk(resourceIds, crc.maxDispatchCount, func(resourceIdChunk []string) {
Expand Down
14 changes: 12 additions & 2 deletions pkg/tuple/onrbytypeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ func (s *ONRByTypeSet) IsEmpty() bool {
return len(s.byType) == 0
}

// Len returns the number of keys in the set.
func (s *ONRByTypeSet) Len() int {
// KeyLen returns the number of keys in the set.
func (s *ONRByTypeSet) KeyLen() int {
return len(s.byType)
}

// ValueLen returns the number of values in the set.
func (s *ONRByTypeSet) ValueLen() int {
var total int
for _, vals := range s.byType {
total += len(vals)
}

return total
}
Loading