this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Pre-allocate ops slices that are appended in a loop where possible. (#743)

This ensures that only one larger allocation is done instead of multiple
small ones, reducing pressure on the garbage collector.

authored by

bnewbold and committed by
GitHub
5ea12810 f9efd8cf

+7 -9
+1 -1
backfill/backfill.go
··· 468 468 return fmt.Errorf("failed to read event repo: %w", err) 469 469 } 470 470 471 - var ops []*BufferedOp 471 + ops := make([]*BufferedOp, 0, len(evt.Ops)) 472 472 for _, op := range evt.Ops { 473 473 kind := repomgr.EventKind(op.Action) 474 474 switch kind {
+2 -4
cmd/supercollider/main.go
··· 586 586 587 587 // HandleRepoEvent is the callback for the RepoManager 588 588 func (s *Server) HandleRepoEvent(ctx context.Context, evt *repomgr.RepoEvent) { 589 - var outops []*comatproto.SyncSubscribeRepos_RepoOp 589 + outops := make([]*comatproto.SyncSubscribeRepos_RepoOp, 0, len(evt.Ops)) 590 590 for _, op := range evt.Ops { 591 591 link := (*lexutil.LexLink)(op.RecCid) 592 592 outops = append(outops, &comatproto.SyncSubscribeRepos_RepoOp{ ··· 596 596 }) 597 597 } 598 598 599 - toobig := false 600 - 601 599 if err := s.Events.AddEvent(ctx, &events.XRPCStreamEvent{ 602 600 RepoCommit: &comatproto.SyncSubscribeRepos_Commit{ 603 601 Repo: s.Dids[evt.User-1], ··· 606 604 Commit: lexutil.LexLink(evt.NewRoot), 607 605 Time: time.Now().Format(util.ISO8601), 608 606 Ops: outops, 609 - TooBig: toobig, 607 + TooBig: false, 610 608 }, 611 609 PrivUid: evt.User, 612 610 }); err != nil {
+1 -1
indexer/indexer.go
··· 86 86 87 87 log.Debugw("Handling Repo Event!", "uid", evt.User) 88 88 89 - var outops []*comatproto.SyncSubscribeRepos_RepoOp 89 + outops := make([]*comatproto.SyncSubscribeRepos_RepoOp, 0, len(evt.Ops)) 90 90 for _, op := range evt.Ops { 91 91 link := (*lexutil.LexLink)(op.RecCid) 92 92 outops = append(outops, &comatproto.SyncSubscribeRepos_RepoOp{
+3 -3
repomgr/repomgr.go
··· 576 576 577 577 } 578 578 579 - var evtops []RepoOp 579 + evtops := make([]RepoOp, 0, len(ops)) 580 580 581 581 for _, op := range ops { 582 582 parts := strings.SplitN(op.Path, "/", 2) ··· 679 679 return err 680 680 } 681 681 682 - var ops []RepoOp 682 + ops := make([]RepoOp, 0, len(writes)) 683 683 for _, w := range writes { 684 684 switch { 685 685 case w.RepoApplyWrites_Create != nil: ··· 826 826 return fmt.Errorf("diff trees (curhead: %s): %w", curhead, err) 827 827 } 828 828 829 - var ops []RepoOp 829 + ops := make([]RepoOp, 0, len(diffops)) 830 830 for _, op := range diffops { 831 831 repoOpsImported.Inc() 832 832 out, err := processOp(ctx, bs, op, rm.hydrateRecords)