Skip to content

Commit e8065e4

Browse files
committed
universe: optimize syncer call
This commit allows for a much larger (32x) page size than before. This should allow us to fetch the complete set of roots even faster, given that we should have 100% cache hits for the syncer calls now. We also reduce the overall count of requests by 1 in almost all cases by detecting that the returned page isn't full anymore (instead of reading until we get an empty page).
1 parent 327bdf9 commit e8065e4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

universe/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var (
3838
const (
3939
// MaxPageSize is the maximum page size that can be used when querying
4040
// for asset roots and leaves.
41-
MaxPageSize = 512
41+
MaxPageSize = 16384
4242
)
4343

4444
// IdentifierKey is the compact representation of a universe identifier that can

universe/syncer.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,17 @@ func (s *SimpleSyncer) SyncUniverse(ctx context.Context, host ServerAddr,
525525
// fetchAllRoots fetches all the roots from the remote Universe. This function
526526
// is used in order to isolate any logic related to the specifics of how we
527527
// fetch the data from the universe server.
528-
func (s *SimpleSyncer) fetchAllRoots(ctx context.Context, diffEngine DiffEngine) ([]Root, error) {
528+
func (s *SimpleSyncer) fetchAllRoots(ctx context.Context,
529+
diffEngine DiffEngine) ([]Root, error) {
530+
529531
offset := int32(0)
530532
pageSize := defaultPageSize
531533
roots := make([]Root, 0)
532534

533535
for {
534536
log.Debugf("Fetching roots in range: %v to %v", offset,
535537
offset+pageSize)
538+
536539
tempRoots, err := diffEngine.RootNodes(
537540
ctx, RootNodesQuery{
538541
WithAmountsById: false,
@@ -541,16 +544,17 @@ func (s *SimpleSyncer) fetchAllRoots(ctx context.Context, diffEngine DiffEngine)
541544
Limit: pageSize,
542545
},
543546
)
544-
545547
if err != nil {
546548
return nil, err
547549
}
548550

549-
if len(tempRoots) == 0 {
551+
roots = append(roots, tempRoots...)
552+
553+
// If we're getting a partial page, then we know we're done.
554+
if len(tempRoots) < int(pageSize) {
550555
break
551556
}
552557

553-
roots = append(roots, tempRoots...)
554558
offset += pageSize
555559
}
556560

0 commit comments

Comments
 (0)