Skip to content

Commit

Permalink
polish: only diff when adt roots are different
Browse files Browse the repository at this point in the history
- increase performace by avoid unnecessary adt walks.
  • Loading branch information
frrist committed Nov 16, 2020
1 parent d25e5d1 commit f73f792
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
28 changes: 28 additions & 0 deletions chain/actors/builtin/market/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ import (
)

func DiffDealProposals(pre, cur DealProposals) (*DealProposalChanges, error) {
preRoot, err := pre.array().Root()
if err != nil {
return nil, err
}
curRoot, err := cur.array().Root()
if err != nil {
return nil, err
}

results := new(DealProposalChanges)
// no change.
if curRoot.Equals(preRoot) {
return results, nil
}

if err := adt.DiffAdtArray(pre.array(), cur.array(), &marketProposalsDiffer{results, pre, cur}); err != nil {
return nil, fmt.Errorf("diffing deal states: %w", err)
}
Expand Down Expand Up @@ -45,7 +59,21 @@ func (d *marketProposalsDiffer) Remove(key uint64, val *cbg.Deferred) error {
}

func DiffDealStates(pre, cur DealStates) (*DealStateChanges, error) {
preRoot, err := pre.array().Root()
if err != nil {
return nil, err
}
curRoot, err := cur.array().Root()
if err != nil {
return nil, err
}

results := new(DealStateChanges)
// no change.
if curRoot.Equals(preRoot) {
return results, nil
}

if err := adt.DiffAdtArray(pre.array(), cur.array(), &marketStatesDiffer{results, pre, cur}); err != nil {
return nil, fmt.Errorf("diffing deal states: %w", err)
}
Expand Down
36 changes: 32 additions & 4 deletions chain/actors/builtin/miner/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
)

func DiffPreCommits(pre, cur State) (*PreCommitChanges, error) {
results := new(PreCommitChanges)

prep, err := pre.precommits()
if err != nil {
return nil, err
Expand All @@ -19,6 +17,22 @@ func DiffPreCommits(pre, cur State) (*PreCommitChanges, error) {
return nil, err
}

preRoot, err := prep.Root()
if err != nil {
return nil, err
}

curRoot, err := curp.Root()
if err != nil {
return nil, err
}

results := new(PreCommitChanges)
// no change.
if curRoot.Equals(preRoot) {
return results, nil
}

err = adt.DiffAdtMap(prep, curp, &preCommitDiffer{results, pre, cur})
if err != nil {
return nil, err
Expand Down Expand Up @@ -63,8 +77,6 @@ func (m *preCommitDiffer) Remove(key string, val *cbg.Deferred) error {
}

func DiffSectors(pre, cur State) (*SectorChanges, error) {
results := new(SectorChanges)

pres, err := pre.sectors()
if err != nil {
return nil, err
Expand All @@ -75,6 +87,22 @@ func DiffSectors(pre, cur State) (*SectorChanges, error) {
return nil, err
}

preRoot, err := pres.Root()
if err != nil {
return nil, err
}

curRoot, err := curs.Root()
if err != nil {
return nil, err
}

results := new(SectorChanges)
// no change.
if curRoot.Equals(preRoot) {
return results, nil
}

err = adt.DiffAdtArray(pres, curs, &sectorDiffer{results, pre, cur})
if err != nil {
return nil, err
Expand Down
16 changes: 15 additions & 1 deletion chain/actors/builtin/power/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type ClaimInfo struct {
}

func DiffClaims(pre, cur State) (*ClaimChanges, error) {
results := new(ClaimChanges)

prec, err := pre.claims()
if err != nil {
Expand All @@ -38,6 +37,21 @@ func DiffClaims(pre, cur State) (*ClaimChanges, error) {
return nil, err
}

preRoot, err := prec.Root()
if err != nil {
return nil, err
}
curRoot, err := curc.Root()
if err != nil {
return nil, err
}

results := new(ClaimChanges)
// no change.
if preRoot.Equals(curRoot) {
return results, nil
}

if err := adt.DiffAdtMap(prec, curc, &claimDiffer{results, pre, cur}); err != nil {
return nil, err
}
Expand Down

0 comments on commit f73f792

Please sign in to comment.