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

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

Merged
merged 1 commit into from
Sep 8, 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
2 changes: 1 addition & 1 deletion backfill/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func (bf *Backfiller) HandleEvent(ctx context.Context, evt *atproto.SyncSubscrib
return fmt.Errorf("failed to read event repo: %w", err)
}

var ops []*BufferedOp
ops := make([]*BufferedOp, 0, len(evt.Ops))
for _, op := range evt.Ops {
kind := repomgr.EventKind(op.Action)
switch kind {
Expand Down
6 changes: 2 additions & 4 deletions cmd/supercollider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func initSpeedyRepoMan(key *godid.PrivKey) (*repomgr.RepoManager, *godid.PrivKey

// HandleRepoEvent is the callback for the RepoManager
func (s *Server) HandleRepoEvent(ctx context.Context, evt *repomgr.RepoEvent) {
var outops []*comatproto.SyncSubscribeRepos_RepoOp
outops := make([]*comatproto.SyncSubscribeRepos_RepoOp, 0, len(evt.Ops))
for _, op := range evt.Ops {
link := (*lexutil.LexLink)(op.RecCid)
outops = append(outops, &comatproto.SyncSubscribeRepos_RepoOp{
Expand All @@ -596,8 +596,6 @@ func (s *Server) HandleRepoEvent(ctx context.Context, evt *repomgr.RepoEvent) {
})
}

toobig := false

if err := s.Events.AddEvent(ctx, &events.XRPCStreamEvent{
RepoCommit: &comatproto.SyncSubscribeRepos_Commit{
Repo: s.Dids[evt.User-1],
Expand All @@ -606,7 +604,7 @@ func (s *Server) HandleRepoEvent(ctx context.Context, evt *repomgr.RepoEvent) {
Commit: lexutil.LexLink(evt.NewRoot),
Time: time.Now().Format(util.ISO8601),
Ops: outops,
TooBig: toobig,
TooBig: false,
},
PrivUid: evt.User,
}); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (ix *Indexer) HandleRepoEvent(ctx context.Context, evt *repomgr.RepoEvent)

log.Debugw("Handling Repo Event!", "uid", evt.User)

var outops []*comatproto.SyncSubscribeRepos_RepoOp
outops := make([]*comatproto.SyncSubscribeRepos_RepoOp, 0, len(evt.Ops))
for _, op := range evt.Ops {
link := (*lexutil.LexLink)(op.RecCid)
outops = append(outops, &comatproto.SyncSubscribeRepos_RepoOp{
Expand Down
6 changes: 3 additions & 3 deletions repomgr/repomgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func (rm *RepoManager) HandleExternalUserEvent(ctx context.Context, pdsid uint,

}

var evtops []RepoOp
evtops := make([]RepoOp, 0, len(ops))

for _, op := range ops {
parts := strings.SplitN(op.Path, "/", 2)
Expand Down Expand Up @@ -679,7 +679,7 @@ func (rm *RepoManager) BatchWrite(ctx context.Context, user models.Uid, writes [
return err
}

var ops []RepoOp
ops := make([]RepoOp, 0, len(writes))
for _, w := range writes {
switch {
case w.RepoApplyWrites_Create != nil:
Expand Down Expand Up @@ -826,7 +826,7 @@ func (rm *RepoManager) ImportNewRepo(ctx context.Context, user models.Uid, repoD
return fmt.Errorf("diff trees (curhead: %s): %w", curhead, err)
}

var ops []RepoOp
ops := make([]RepoOp, 0, len(diffops))
for _, op := range diffops {
repoOpsImported.Inc()
out, err := processOp(ctx, bs, op, rm.hydrateRecords)
Expand Down
Loading