From f229fe945b3b53cabc94e50bcc5fb2a2efd56083 Mon Sep 17 00:00:00 2001 From: wit Date: Sat, 13 Dec 2025 11:49:41 +0800 Subject: [PATCH] eth/tracers: cache callstack frame index in `OnLog` --- eth/tracers/native/call.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/eth/tracers/native/call.go b/eth/tracers/native/call.go index c2247d1ce4..ce693f3ca5 100644 --- a/eth/tracers/native/call.go +++ b/eth/tracers/native/call.go @@ -246,13 +246,17 @@ func (t *callTracer) OnLog(log *types.Log) { if t.interrupt.Load() { return } + + // Cache the index of the current frame to avoid repeated calculations + lastIdx := len(t.callstack) - 1 + l := callLog{ Address: log.Address, Topics: log.Topics, Data: log.Data, - Position: hexutil.Uint(len(t.callstack[len(t.callstack)-1].Calls)), + Position: hexutil.Uint(len(t.callstack[lastIdx].Calls)), } - t.callstack[len(t.callstack)-1].Logs = append(t.callstack[len(t.callstack)-1].Logs, l) + t.callstack[lastIdx].Logs = append(t.callstack[lastIdx].Logs, l) } // GetResult returns the json-encoded nested list of call traces, and any