Skip to content

Commit

Permalink
fix: avoid transferring traces to JS (#5139)
Browse files Browse the repository at this point in the history
  • Loading branch information
agostbiro committed Apr 19, 2024
1 parent abb6316 commit 6447e80
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/wicked-walls-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/ed": patch
---

fix: avoid transferring traces to JS if there are no plugins that need them to improve performance
9 changes: 8 additions & 1 deletion crates/tools/js/benchmark/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,15 @@ function numIterations(scenarioName) {
// Run fast scenarios repeatedly to get more reliable results
if (scenarioName.includes("safe-contracts")) {
return 15;
} else if (scenarioName.includes("seaport")) {
} else if (
scenarioName.includes("seaport") ||
scenarioName.includes("openzeppelin") ||
scenarioName.includes("rocketpool") ||
scenarioName.includes("uniswap")
) {
return 5;
} else if (scenarioName.includes("neptune-mutual")) {
return 3;
} else {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,41 +368,49 @@ export class EdrProviderWrapper
);
const response = JSON.parse(responseObject.json);

const rawTraces = responseObject.traces;
for (const rawTrace of rawTraces) {
const trace = rawTrace.trace();
for (const traceItem of trace) {
if ("pc" in traceItem) {
if (this._node._vm.evm.events.listenerCount("step") > 0) {
this._node._vm.evm.events.emit(
"step",
edrTracingStepToMinimalInterpreterStep(traceItem)
);
}
if (this._rawTraceCallbacks.onStep !== undefined) {
await this._rawTraceCallbacks.onStep(traceItem);
}
} else if ("executionResult" in traceItem) {
if (this._node._vm.evm.events.listenerCount("afterMessage") > 0) {
this._node._vm.evm.events.emit(
"afterMessage",
edrTracingMessageResultToMinimalEVMResult(traceItem)
);
}
if (this._rawTraceCallbacks.onAfterMessage !== undefined) {
await this._rawTraceCallbacks.onAfterMessage(
traceItem.executionResult
);
}
} else {
if (this._node._vm.evm.events.listenerCount("beforeMessage") > 0) {
this._node._vm.evm.events.emit(
"beforeMessage",
edrTracingMessageToMinimalMessage(traceItem)
);
}
if (this._rawTraceCallbacks.onBeforeMessage !== undefined) {
await this._rawTraceCallbacks.onBeforeMessage(traceItem);
const needsTraces =
this._node._vm.evm.events.eventNames().length > 0 ||
this._rawTraceCallbacks.onStep !== undefined ||
this._rawTraceCallbacks.onAfterMessage !== undefined ||
this._rawTraceCallbacks.onBeforeMessage !== undefined;

if (needsTraces) {
const rawTraces = responseObject.traces;
for (const rawTrace of rawTraces) {
const trace = rawTrace.trace();
for (const traceItem of trace) {
if ("pc" in traceItem) {
if (this._node._vm.evm.events.listenerCount("step") > 0) {
this._node._vm.evm.events.emit(
"step",
edrTracingStepToMinimalInterpreterStep(traceItem)
);
}
if (this._rawTraceCallbacks.onStep !== undefined) {
await this._rawTraceCallbacks.onStep(traceItem);
}
} else if ("executionResult" in traceItem) {
if (this._node._vm.evm.events.listenerCount("afterMessage") > 0) {
this._node._vm.evm.events.emit(
"afterMessage",
edrTracingMessageResultToMinimalEVMResult(traceItem)
);
}
if (this._rawTraceCallbacks.onAfterMessage !== undefined) {
await this._rawTraceCallbacks.onAfterMessage(
traceItem.executionResult
);
}
} else {
if (this._node._vm.evm.events.listenerCount("beforeMessage") > 0) {
this._node._vm.evm.events.emit(
"beforeMessage",
edrTracingMessageToMinimalMessage(traceItem)
);
}
if (this._rawTraceCallbacks.onBeforeMessage !== undefined) {
await this._rawTraceCallbacks.onBeforeMessage(traceItem);
}
}
}
}
Expand Down

0 comments on commit 6447e80

Please sign in to comment.