Skip to content

Commit

Permalink
Problem: memiavl inefficient code in rare path (#1620)
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang authored Oct 4, 2024
1 parent a87e03b commit c96cdaf
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions memiavl/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,17 @@ func (db *DB) ApplyChangeSets(changeSets []*NamedChangeSet) error {

if len(db.pendingLog.Changesets) == 0 {
db.pendingLog.Changesets = changeSets
} else {
// slow path, merge into exist changesets one by one
for _, cs := range changeSets {
if err := db.applyChangeSet(cs.Name, cs.Changeset); err != nil {
return err
}
}
return db.MultiTree.ApplyChangeSets(changeSets)
}

return db.MultiTree.ApplyChangeSets(changeSets)
// slow path, merge into exist changesets one store at a time,
// should not happen in normal state machine life-cycle.
for _, cs := range changeSets {
if err := db.applyChangeSet(cs.Name, cs.Changeset); err != nil {
return err
}
}
return nil
}

// ApplyChangeSet wraps MultiTree.ApplyChangeSet, it also append the changesets in the pending log,
Expand Down

0 comments on commit c96cdaf

Please sign in to comment.