Skip to content

Commit 2ba5ea3

Browse files
authored
Revert "refactor: reduce number of heap allocations in tracing (#952)" (#959)
This reverts commit b84f4ed.
1 parent ee0410e commit 2ba5ea3

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

core/types/l2trace.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type ExecutionResult struct {
7070
// currently they are just `from` and `to` account
7171
AccountsAfter []*AccountWrapper `json:"accountAfter"`
7272

73-
StructLogs []StructLogRes `json:"structLogs"`
73+
StructLogs []*StructLogRes `json:"structLogs"`
7474
CallTrace json.RawMessage `json:"callTrace"`
7575
}
7676

@@ -91,8 +91,8 @@ type StructLogRes struct {
9191

9292
// NewStructLogResBasic Basic StructLogRes skeleton, Stack&Memory&Storage&ExtraData are separated from it for GC optimization;
9393
// still need to fill in with Stack&Memory&Storage&ExtraData
94-
func NewStructLogResBasic(pc uint64, op string, gas, gasCost uint64, depth int, refundCounter uint64, err error) StructLogRes {
95-
logRes := StructLogRes{
94+
func NewStructLogResBasic(pc uint64, op string, gas, gasCost uint64, depth int, refundCounter uint64, err error) *StructLogRes {
95+
logRes := &StructLogRes{
9696
Pc: pc,
9797
Op: op,
9898
Gas: gas,

core/vm/logger.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ type StructLog struct {
7979
Err error `json:"-"`
8080
}
8181

82-
func NewStructlog(pc uint64, op OpCode, gas, cost uint64, depth int, err error) StructLog {
83-
return StructLog{
82+
func NewStructlog(pc uint64, op OpCode, gas, cost uint64, depth int, err error) *StructLog {
83+
return &StructLog{
8484
Pc: pc,
8585
Op: op,
8686
Gas: gas,
@@ -90,6 +90,14 @@ func NewStructlog(pc uint64, op OpCode, gas, cost uint64, depth int, err error)
9090
}
9191
}
9292

93+
func (s *StructLog) clean() {
94+
s.Memory.Reset()
95+
s.Stack = s.Stack[:0]
96+
s.ReturnData.Reset()
97+
s.Storage = nil
98+
s.Err = nil
99+
}
100+
93101
// overrides for gencodec
94102
type structLogMarshaling struct {
95103
Gas math.HexOrDecimal64
@@ -151,7 +159,7 @@ type StructLogger struct {
151159
createdAccount *types.AccountWrapper
152160

153161
callStackLogInd []int
154-
logs []StructLog
162+
logs []*StructLog
155163
output []byte
156164
err error
157165
}
@@ -351,7 +359,7 @@ func (l *StructLogger) TracedBytecodes() map[common.Hash]CodeInfo {
351359
func (l *StructLogger) CreatedAccount() *types.AccountWrapper { return l.createdAccount }
352360

353361
// StructLogs returns the captured log entries.
354-
func (l *StructLogger) StructLogs() []StructLog { return l.logs }
362+
func (l *StructLogger) StructLogs() []*StructLog { return l.logs }
355363

356364
// Error returns the VM error captured by the trace.
357365
func (l *StructLogger) Error() error { return l.err }
@@ -360,7 +368,7 @@ func (l *StructLogger) Error() error { return l.err }
360368
func (l *StructLogger) Output() []byte { return l.output }
361369

362370
// WriteTrace writes a formatted trace to the given writer
363-
func WriteTrace(writer io.Writer, logs []StructLog) {
371+
func WriteTrace(writer io.Writer, logs []*StructLog) {
364372
for _, log := range logs {
365373
fmt.Fprintf(writer, "%-16spc=%08d gas=%v cost=%v", log.Op, log.Pc, log.Gas, log.GasCost)
366374
if log.Err != nil {
@@ -480,8 +488,8 @@ func (t *mdLogger) CaptureEnter(typ OpCode, from common.Address, to common.Addre
480488
func (t *mdLogger) CaptureExit(output []byte, gasUsed uint64, err error) {}
481489

482490
// FormatLogs formats EVM returned structured logs for json output
483-
func FormatLogs(logs []StructLog) []types.StructLogRes {
484-
formatted := make([]types.StructLogRes, 0, len(logs))
491+
func FormatLogs(logs []*StructLog) []*types.StructLogRes {
492+
formatted := make([]*types.StructLogRes, 0, len(logs))
485493

486494
for _, trace := range logs {
487495
logRes := types.NewStructLogResBasic(trace.Pc, trace.Op.String(), trace.Gas, trace.GasCost, trace.Depth, trace.RefundCounter, trace.Err)

eth/tracers/api_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func TestTraceCall(t *testing.T) {
227227
Gas: params.TxGas,
228228
Failed: false,
229229
ReturnValue: "",
230-
StructLogs: []types.StructLogRes{},
230+
StructLogs: []*types.StructLogRes{},
231231
},
232232
},
233233
// Standard JSON trace upon the head, plain transfer.
@@ -245,7 +245,7 @@ func TestTraceCall(t *testing.T) {
245245
Gas: params.TxGas,
246246
Failed: false,
247247
ReturnValue: "",
248-
StructLogs: []types.StructLogRes{},
248+
StructLogs: []*types.StructLogRes{},
249249
},
250250
},
251251
// Standard JSON trace upon the non-existent block, error expects
@@ -275,7 +275,7 @@ func TestTraceCall(t *testing.T) {
275275
Gas: params.TxGas,
276276
Failed: false,
277277
ReturnValue: "",
278-
StructLogs: []types.StructLogRes{},
278+
StructLogs: []*types.StructLogRes{},
279279
},
280280
},
281281
// Standard JSON trace upon the pending block
@@ -293,7 +293,7 @@ func TestTraceCall(t *testing.T) {
293293
Gas: params.TxGas,
294294
Failed: false,
295295
ReturnValue: "",
296-
StructLogs: []types.StructLogRes{},
296+
StructLogs: []*types.StructLogRes{},
297297
},
298298
},
299299
}
@@ -347,7 +347,7 @@ func TestTraceTransaction(t *testing.T) {
347347
Gas: params.TxGas,
348348
Failed: false,
349349
ReturnValue: "",
350-
StructLogs: []types.StructLogRes{},
350+
StructLogs: []*types.StructLogRes{},
351351
}) {
352352
t.Error("Transaction tracing result is different")
353353
}

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 5 // Minor version component of the current release
27-
VersionPatch = 21 // Patch version component of the current release
27+
VersionPatch = 22 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)