perf(prover): preallocate slices (#119)

* chore(prover): add prealloc linter
* perf(prover): preallocate slices
This commit is contained in:
Håvard Anda Estensen
2024-11-19 10:19:50 +01:00
committed by GitHub
parent 0b797594bd
commit 9713fef2a6
6 changed files with 14 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ linters:
# - gosimple
# - govet
- ineffassign
- prealloc
run:
issues-exit-code: 1

View File

@@ -176,7 +176,7 @@ func cmdSetup(cmd *cobra.Command, args []string) error {
}
// first, we need to collect the verifying keys
var allowedVkForAggregation []plonk.VerifyingKey
allowedVkForAggregation := make([]plonk.VerifyingKey, 0, len(cfg.Aggregation.AllowedInputs))
for _, allowedInput := range cfg.Aggregation.AllowedInputs {
// first if it's a dummy circuit, we just run the setup here, we don't need to persist it.
if isDummyCircuit(allowedInput) {
@@ -223,7 +223,7 @@ func cmdSetup(cmd *cobra.Command, args []string) error {
}
// now for each aggregation circuit, we update the setup if needed, and collect the verifying keys
var allowedVkForEmulation []plonk.VerifyingKey
allowedVkForEmulation := make([]plonk.VerifyingKey, 0, len(cfg.Aggregation.NumProofs))
for _, numProofs := range cfg.Aggregation.NumProofs {
c := circuits.CircuitID(fmt.Sprintf("%s-%d", string(circuits.AggregationCircuitID), numProofs))
logrus.Infof("setting up %s (numProofs=%d)", c, numProofs)

View File

@@ -53,7 +53,7 @@ func (kv *Mapping[K, V]) Update(key K, value V) {
// Returns the list of all the keys
func (kv *Mapping[K, V]) ListAllKeys() []K {
var res []K
res := make([]K, 0, len(kv.innerMap))
for k := range kv.innerMap {
res = append(res, k)
}
@@ -102,7 +102,7 @@ func (kv *Mapping[K, V]) Exists(ks ...K) bool {
// ToSlice lists all entries in a slice of tuple
func (kv *Mapping[K, V]) ListValues() []V {
var res []V
res := make([]V, 0, len(kv.innerMap))
for _, v := range kv.innerMap {
res = append(res, v)
}

View File

@@ -239,11 +239,13 @@ func (addr *Addresses) assignMainColumns(
split := splitAt(nbEcRecover)
n := nbRowsPerEcRec
var (
hashHi, hashLo, isHash, trimmedHi []field.Element
)
permTrace := keccak.GenerateTrace(pkModule.Data.ScanStreams(run))
hashHi := make([]field.Element, 0, len(permTrace.HashOutPut))
hashLo := make([]field.Element, 0, len(permTrace.HashOutPut))
isHash := make([]field.Element, 0, len(permTrace.HashOutPut))
trimmedHi := make([]field.Element, 0, len(permTrace.HashOutPut))
var v, w, u field.Element
for _, digest := range permTrace.HashOutPut {

View File

@@ -103,14 +103,12 @@ func (td *txnData) assignTxnDataFromPK(
rlpTxnHashes [][32]byte,
nbRowsPerTxInTxnData int,
) {
// compute the hash of public keys
var (
pkHash [][]byte
hasher = sha3.NewLegacyKeccak256()
maxNbTx = ac.Inputs.settings.MaxNbTx
)
// compute the hash of public keys
pkHash := make([][]byte, 0, len(rlpTxnHashes))
for i := range rlpTxnHashes {
pk, _, _, _, err := generateDeterministicSignature(rlpTxnHashes[i][:])
if err != nil {

View File

@@ -747,7 +747,7 @@ func (stitcher *Stitcher) AddFrame(frame StateAccessLog) {
// this is necessary because we need to list the keys in the columns in a sorted manner. and in order to use the sort function we need a slice
func MapKeysToSlice[K comparable, V any](accountSet map[K]V) []K {
// obtain the slice of key values from a map
var accounts []K
accounts := make([]K, 0, len(accountSet))
for addressIterator := range accountSet {
accounts = append(accounts, addressIterator)
}