Skip to content

Commit f247a2c

Browse files
committed
x
1 parent 6ea3b8d commit f247a2c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

execution/evm/store.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ func NewEVMStore(db ds.Batching) *EVMStore {
100100

101101
// execMetaKey returns the datastore key for ExecMeta at a given height.
102102
func execMetaKey(height uint64) ds.Key {
103-
heightBytes := make([]byte, 8)
104-
binary.BigEndian.PutUint64(heightBytes, height)
105-
return ds.NewKey(evmStorePrefix + "execmeta/" + string(heightBytes))
103+
var buf [8]byte
104+
binary.BigEndian.PutUint64(buf[:], height)
105+
return ds.NewKey(evmStorePrefix + "execmeta/" + string(buf[:]))
106106
}
107107

108108
// GetExecMeta retrieves execution metadata for the given height.
@@ -133,7 +133,9 @@ func (s *EVMStore) GetExecMeta(ctx context.Context, height uint64) (*ExecMeta, e
133133
// SaveExecMeta persists execution metadata for the given height.
134134
func (s *EVMStore) SaveExecMeta(ctx context.Context, meta *ExecMeta) error {
135135
key := execMetaKey(meta.Height)
136-
data, err := proto.Marshal(meta.ToProto())
136+
// Use stack-allocated buffer to avoid heap allocation for small metadata.
137+
var buf [1024]byte
138+
data, err := proto.MarshalOptions{}.MarshalAppend(buf[:0], meta.ToProto())
137139
if err != nil {
138140
return fmt.Errorf("failed to marshal exec meta: %w", err)
139141
}
@@ -180,9 +182,9 @@ func (s *EVMStore) PruneExec(ctx context.Context, height uint64) error {
180182
}
181183

182184
// Persist updated last pruned height.
183-
buf := make([]byte, 8)
184-
binary.BigEndian.PutUint64(buf, height)
185-
if err := batch.Put(ctx, ds.NewKey(lastPrunedExecMetaKey), buf); err != nil {
185+
var buf [8]byte
186+
binary.BigEndian.PutUint64(buf[:], height)
187+
if err := batch.Put(ctx, ds.NewKey(lastPrunedExecMetaKey), buf[:]); err != nil {
186188
return fmt.Errorf("failed to update last pruned execmeta height: %w", err)
187189
}
188190

0 commit comments

Comments
 (0)