prysm-pulse/shared/aggregation/attestations/attestations_bench_test.go

105 lines
3.1 KiB
Go
Raw Normal View History

package attestations
import (
Attestation aggregation: optimizations and benchmarks (#7938) * profitablity tests * cleanup benchmark * fix deduplication function * dedup: move method to atts list * proper substring handling * refactor validate method * update benchmarks * prepare proposer test * remove redundant code * reset test * remove dedup from maxcover - moved to proposer * remove redundant test * remove lower level check for bit length * optimize candidate validation on att aggregation * restore test * fix test * fix test * remove dedup functionality * add benchmark * optimize list usage * Attestation aggregration: remove redundant dedup routine * fix func call * experiment with bitset based cover * add benchmark * samplem implementation using Bilist64 * add tests * remove redundant code * remove tmp comments * unskip test * update benchmarks * gazelle * process err * optimized max-cover * Max-cover: optimized implementation based on Bitlist64 * gazelle * re-arrange overlaps check * minor comments * add Bitlists64WithMultipleBitSet * update benchmarks * gazelle * add TestAggregateAttestations_rearrangeProcessedAttestations * minor updates to rearrange method * add link to design doc * remove redundant methods * simplify test * add TestAggregateAttestations_aggregateAttestations * fix issues * fix assignment * use ToBitlist(), ToBitlist64() * fixes test * benchmarks * fix typo * allow opt_max_cover opt-int flag * update benchmarks * reset e2e * fix test * enable opt_max_cover in e2e tests Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-02-04 00:58:33 +00:00
"fmt"
"testing"
2021-05-26 18:33:46 +00:00
"github.com/prysmaticlabs/prysm/shared/copyutil"
"github.com/prysmaticlabs/go-bitfield"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
aggtesting "github.com/prysmaticlabs/prysm/shared/aggregation/testing"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bls/common"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
Applies assertion funcs to shared tests (part 1) (#6626) * Update kv aggregated_test.go * Update block_test.go * Update forkchoice_test.go * Update unaggregated_test.go * Update prepare_forkchoice_test.go * Update prune_expired_test.go * Update atts service_test.go * Update service_attester_test.go * Update service_proposer_test.go * Upate exit service_test.go * Gaz * Merge branch 'master' of github.com:prysmaticlabs/prysm * Move averageBalance from log.go to info.go * Move avg balance from log.go to info.go * Add info test * Remove unused logEpochData in log.go * Gaz * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * aggregation tests * attestation util tests * bench util tests * block util tests * herumi tests * bytesutil tests * Merge refs/heads/master into testutil-shared * Merge refs/heads/master into testutil-shared * Merge refs/heads/master into testutil-shared * Merge refs/heads/master into testutil-shared * Merge refs/heads/master into testutil-shared * Update shared/aggregation/attestations/attestations_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Merge branch 'master' of github.com:prysmaticlabs/prysm into testutil-shared * Fixed ordering * Merge branch 'testutil-shared' of github.com:prysmaticlabs/prysm into testutil-shared * Update shared/aggregation/attestations/attestations_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update shared/bytesutil/bytes_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
2020-07-18 16:31:42 +00:00
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func BenchmarkAggregateAttestations_Aggregate(b *testing.B) {
// Override expensive BLS aggregation method with cheap no-op such that this benchmark profiles
// the logic of aggregation selection rather than BLS logic.
aggregateSignatures = func(sigs []common.Signature) common.Signature {
return sigs[0]
}
signatureFromBytes = func(sig []byte) (common.Signature, error) {
return bls.NewAggregateSignature(), nil
}
defer func() {
aggregateSignatures = bls.AggregateSignatures
signatureFromBytes = bls.SignatureFromBytes
}()
bitlistLen := params.BeaconConfig().MaxValidatorsPerCommittee
tests := []struct {
name string
inputs []bitfield.Bitlist
}{
{
Attestation aggregation: optimizations and benchmarks (#7938) * profitablity tests * cleanup benchmark * fix deduplication function * dedup: move method to atts list * proper substring handling * refactor validate method * update benchmarks * prepare proposer test * remove redundant code * reset test * remove dedup from maxcover - moved to proposer * remove redundant test * remove lower level check for bit length * optimize candidate validation on att aggregation * restore test * fix test * fix test * remove dedup functionality * add benchmark * optimize list usage * Attestation aggregration: remove redundant dedup routine * fix func call * experiment with bitset based cover * add benchmark * samplem implementation using Bilist64 * add tests * remove redundant code * remove tmp comments * unskip test * update benchmarks * gazelle * process err * optimized max-cover * Max-cover: optimized implementation based on Bitlist64 * gazelle * re-arrange overlaps check * minor comments * add Bitlists64WithMultipleBitSet * update benchmarks * gazelle * add TestAggregateAttestations_rearrangeProcessedAttestations * minor updates to rearrange method * add link to design doc * remove redundant methods * simplify test * add TestAggregateAttestations_aggregateAttestations * fix issues * fix assignment * use ToBitlist(), ToBitlist64() * fixes test * benchmarks * fix typo * allow opt_max_cover opt-int flag * update benchmarks * reset e2e * fix test * enable opt_max_cover in e2e tests Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-02-04 00:58:33 +00:00
name: "256 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(256, bitlistLen),
},
{
name: "256 attestations with 64 random bits set",
inputs: aggtesting.BitlistsWithSingleBitSet(256, bitlistLen),
},
{
name: "512 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(512, bitlistLen),
},
{
Attestation aggregation: optimizations and benchmarks (#7938) * profitablity tests * cleanup benchmark * fix deduplication function * dedup: move method to atts list * proper substring handling * refactor validate method * update benchmarks * prepare proposer test * remove redundant code * reset test * remove dedup from maxcover - moved to proposer * remove redundant test * remove lower level check for bit length * optimize candidate validation on att aggregation * restore test * fix test * fix test * remove dedup functionality * add benchmark * optimize list usage * Attestation aggregration: remove redundant dedup routine * fix func call * experiment with bitset based cover * add benchmark * samplem implementation using Bilist64 * add tests * remove redundant code * remove tmp comments * unskip test * update benchmarks * gazelle * process err * optimized max-cover * Max-cover: optimized implementation based on Bitlist64 * gazelle * re-arrange overlaps check * minor comments * add Bitlists64WithMultipleBitSet * update benchmarks * gazelle * add TestAggregateAttestations_rearrangeProcessedAttestations * minor updates to rearrange method * add link to design doc * remove redundant methods * simplify test * add TestAggregateAttestations_aggregateAttestations * fix issues * fix assignment * use ToBitlist(), ToBitlist64() * fixes test * benchmarks * fix typo * allow opt_max_cover opt-int flag * update benchmarks * reset e2e * fix test * enable opt_max_cover in e2e tests Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-02-04 00:58:33 +00:00
name: "1024 attestations with 64 random bits set",
inputs: aggtesting.BitlistsWithMultipleBitSet(b, 1024, bitlistLen, 64),
},
}
Attestation aggregation: optimizations and benchmarks (#7938) * profitablity tests * cleanup benchmark * fix deduplication function * dedup: move method to atts list * proper substring handling * refactor validate method * update benchmarks * prepare proposer test * remove redundant code * reset test * remove dedup from maxcover - moved to proposer * remove redundant test * remove lower level check for bit length * optimize candidate validation on att aggregation * restore test * fix test * fix test * remove dedup functionality * add benchmark * optimize list usage * Attestation aggregration: remove redundant dedup routine * fix func call * experiment with bitset based cover * add benchmark * samplem implementation using Bilist64 * add tests * remove redundant code * remove tmp comments * unskip test * update benchmarks * gazelle * process err * optimized max-cover * Max-cover: optimized implementation based on Bitlist64 * gazelle * re-arrange overlaps check * minor comments * add Bitlists64WithMultipleBitSet * update benchmarks * gazelle * add TestAggregateAttestations_rearrangeProcessedAttestations * minor updates to rearrange method * add link to design doc * remove redundant methods * simplify test * add TestAggregateAttestations_aggregateAttestations * fix issues * fix assignment * use ToBitlist(), ToBitlist64() * fixes test * benchmarks * fix typo * allow opt_max_cover opt-int flag * update benchmarks * reset e2e * fix test * enable opt_max_cover in e2e tests Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-02-04 00:58:33 +00:00
runner := func(atts []*ethpb.Attestation) {
attsCopy := make([]*ethpb.Attestation, len(atts))
for i, att := range atts {
2021-05-26 18:33:46 +00:00
attsCopy[i] = copyutil.CopyAttestation(att)
}
Attestation aggregation: optimizations and benchmarks (#7938) * profitablity tests * cleanup benchmark * fix deduplication function * dedup: move method to atts list * proper substring handling * refactor validate method * update benchmarks * prepare proposer test * remove redundant code * reset test * remove dedup from maxcover - moved to proposer * remove redundant test * remove lower level check for bit length * optimize candidate validation on att aggregation * restore test * fix test * fix test * remove dedup functionality * add benchmark * optimize list usage * Attestation aggregration: remove redundant dedup routine * fix func call * experiment with bitset based cover * add benchmark * samplem implementation using Bilist64 * add tests * remove redundant code * remove tmp comments * unskip test * update benchmarks * gazelle * process err * optimized max-cover * Max-cover: optimized implementation based on Bitlist64 * gazelle * re-arrange overlaps check * minor comments * add Bitlists64WithMultipleBitSet * update benchmarks * gazelle * add TestAggregateAttestations_rearrangeProcessedAttestations * minor updates to rearrange method * add link to design doc * remove redundant methods * simplify test * add TestAggregateAttestations_aggregateAttestations * fix issues * fix assignment * use ToBitlist(), ToBitlist64() * fixes test * benchmarks * fix typo * allow opt_max_cover opt-int flag * update benchmarks * reset e2e * fix test * enable opt_max_cover in e2e tests Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-02-04 00:58:33 +00:00
_, err := Aggregate(attsCopy)
require.NoError(b, err)
}
Attestation aggregation: optimizations and benchmarks (#7938) * profitablity tests * cleanup benchmark * fix deduplication function * dedup: move method to atts list * proper substring handling * refactor validate method * update benchmarks * prepare proposer test * remove redundant code * reset test * remove dedup from maxcover - moved to proposer * remove redundant test * remove lower level check for bit length * optimize candidate validation on att aggregation * restore test * fix test * fix test * remove dedup functionality * add benchmark * optimize list usage * Attestation aggregration: remove redundant dedup routine * fix func call * experiment with bitset based cover * add benchmark * samplem implementation using Bilist64 * add tests * remove redundant code * remove tmp comments * unskip test * update benchmarks * gazelle * process err * optimized max-cover * Max-cover: optimized implementation based on Bitlist64 * gazelle * re-arrange overlaps check * minor comments * add Bitlists64WithMultipleBitSet * update benchmarks * gazelle * add TestAggregateAttestations_rearrangeProcessedAttestations * minor updates to rearrange method * add link to design doc * remove redundant methods * simplify test * add TestAggregateAttestations_aggregateAttestations * fix issues * fix assignment * use ToBitlist(), ToBitlist64() * fixes test * benchmarks * fix typo * allow opt_max_cover opt-int flag * update benchmarks * reset e2e * fix test * enable opt_max_cover in e2e tests Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-02-04 00:58:33 +00:00
for _, tt := range tests {
b.Run(fmt.Sprintf("naive_%s", tt.name), func(b *testing.B) {
b.StopTimer()
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
AttestationAggregationStrategy: string(NaiveAggregation),
})
atts := aggtesting.MakeAttestationsFromBitlists(tt.inputs)
defer resetCfg()
b.StartTimer()
for i := 0; i < b.N; i++ {
runner(atts)
}
})
Attestation aggregation: optimizations and benchmarks (#7938) * profitablity tests * cleanup benchmark * fix deduplication function * dedup: move method to atts list * proper substring handling * refactor validate method * update benchmarks * prepare proposer test * remove redundant code * reset test * remove dedup from maxcover - moved to proposer * remove redundant test * remove lower level check for bit length * optimize candidate validation on att aggregation * restore test * fix test * fix test * remove dedup functionality * add benchmark * optimize list usage * Attestation aggregration: remove redundant dedup routine * fix func call * experiment with bitset based cover * add benchmark * samplem implementation using Bilist64 * add tests * remove redundant code * remove tmp comments * unskip test * update benchmarks * gazelle * process err * optimized max-cover * Max-cover: optimized implementation based on Bitlist64 * gazelle * re-arrange overlaps check * minor comments * add Bitlists64WithMultipleBitSet * update benchmarks * gazelle * add TestAggregateAttestations_rearrangeProcessedAttestations * minor updates to rearrange method * add link to design doc * remove redundant methods * simplify test * add TestAggregateAttestations_aggregateAttestations * fix issues * fix assignment * use ToBitlist(), ToBitlist64() * fixes test * benchmarks * fix typo * allow opt_max_cover opt-int flag * update benchmarks * reset e2e * fix test * enable opt_max_cover in e2e tests Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-02-04 00:58:33 +00:00
b.Run(fmt.Sprintf("max-cover_%s", tt.name), func(b *testing.B) {
b.StopTimer()
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
AttestationAggregationStrategy: string(MaxCoverAggregation),
})
Attestation aggregation: optimizations and benchmarks (#7938) * profitablity tests * cleanup benchmark * fix deduplication function * dedup: move method to atts list * proper substring handling * refactor validate method * update benchmarks * prepare proposer test * remove redundant code * reset test * remove dedup from maxcover - moved to proposer * remove redundant test * remove lower level check for bit length * optimize candidate validation on att aggregation * restore test * fix test * fix test * remove dedup functionality * add benchmark * optimize list usage * Attestation aggregration: remove redundant dedup routine * fix func call * experiment with bitset based cover * add benchmark * samplem implementation using Bilist64 * add tests * remove redundant code * remove tmp comments * unskip test * update benchmarks * gazelle * process err * optimized max-cover * Max-cover: optimized implementation based on Bitlist64 * gazelle * re-arrange overlaps check * minor comments * add Bitlists64WithMultipleBitSet * update benchmarks * gazelle * add TestAggregateAttestations_rearrangeProcessedAttestations * minor updates to rearrange method * add link to design doc * remove redundant methods * simplify test * add TestAggregateAttestations_aggregateAttestations * fix issues * fix assignment * use ToBitlist(), ToBitlist64() * fixes test * benchmarks * fix typo * allow opt_max_cover opt-int flag * update benchmarks * reset e2e * fix test * enable opt_max_cover in e2e tests Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2021-02-04 00:58:33 +00:00
atts := aggtesting.MakeAttestationsFromBitlists(tt.inputs)
defer resetCfg()
b.StartTimer()
for i := 0; i < b.N; i++ {
runner(atts)
}
})
b.Run(fmt.Sprintf("opt-max-cover_%s", tt.name), func(b *testing.B) {
b.StopTimer()
resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{
AttestationAggregationStrategy: string(OptMaxCoverAggregation),
})
atts := aggtesting.MakeAttestationsFromBitlists(tt.inputs)
defer resetCfg()
b.StartTimer()
for i := 0; i < b.N; i++ {
runner(atts)
}
})
}
}