Skip to content

Commit 6447e80

Browse files
authoredApr 19, 2024··
fix: avoid transferring traces to JS (#5139)
1 parent abb6316 commit 6447e80

File tree

3 files changed

+56
-36
lines changed

3 files changed

+56
-36
lines changed
 

‎.changeset/wicked-walls-itch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomicfoundation/ed": patch
3+
---
4+
5+
fix: avoid transferring traces to JS if there are no plugins that need them to improve performance

‎crates/tools/js/benchmark/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,15 @@ function numIterations(scenarioName) {
215215
// Run fast scenarios repeatedly to get more reliable results
216216
if (scenarioName.includes("safe-contracts")) {
217217
return 15;
218-
} else if (scenarioName.includes("seaport")) {
218+
} else if (
219+
scenarioName.includes("seaport") ||
220+
scenarioName.includes("openzeppelin") ||
221+
scenarioName.includes("rocketpool") ||
222+
scenarioName.includes("uniswap")
223+
) {
219224
return 5;
225+
} else if (scenarioName.includes("neptune-mutual")) {
226+
return 3;
220227
} else {
221228
return 1;
222229
}

‎packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts

+43-35
Original file line numberDiff line numberDiff line change
@@ -368,41 +368,49 @@ export class EdrProviderWrapper
368368
);
369369
const response = JSON.parse(responseObject.json);
370370

371-
const rawTraces = responseObject.traces;
372-
for (const rawTrace of rawTraces) {
373-
const trace = rawTrace.trace();
374-
for (const traceItem of trace) {
375-
if ("pc" in traceItem) {
376-
if (this._node._vm.evm.events.listenerCount("step") > 0) {
377-
this._node._vm.evm.events.emit(
378-
"step",
379-
edrTracingStepToMinimalInterpreterStep(traceItem)
380-
);
381-
}
382-
if (this._rawTraceCallbacks.onStep !== undefined) {
383-
await this._rawTraceCallbacks.onStep(traceItem);
384-
}
385-
} else if ("executionResult" in traceItem) {
386-
if (this._node._vm.evm.events.listenerCount("afterMessage") > 0) {
387-
this._node._vm.evm.events.emit(
388-
"afterMessage",
389-
edrTracingMessageResultToMinimalEVMResult(traceItem)
390-
);
391-
}
392-
if (this._rawTraceCallbacks.onAfterMessage !== undefined) {
393-
await this._rawTraceCallbacks.onAfterMessage(
394-
traceItem.executionResult
395-
);
396-
}
397-
} else {
398-
if (this._node._vm.evm.events.listenerCount("beforeMessage") > 0) {
399-
this._node._vm.evm.events.emit(
400-
"beforeMessage",
401-
edrTracingMessageToMinimalMessage(traceItem)
402-
);
403-
}
404-
if (this._rawTraceCallbacks.onBeforeMessage !== undefined) {
405-
await this._rawTraceCallbacks.onBeforeMessage(traceItem);
371+
const needsTraces =
372+
this._node._vm.evm.events.eventNames().length > 0 ||
373+
this._rawTraceCallbacks.onStep !== undefined ||
374+
this._rawTraceCallbacks.onAfterMessage !== undefined ||
375+
this._rawTraceCallbacks.onBeforeMessage !== undefined;
376+
377+
if (needsTraces) {
378+
const rawTraces = responseObject.traces;
379+
for (const rawTrace of rawTraces) {
380+
const trace = rawTrace.trace();
381+
for (const traceItem of trace) {
382+
if ("pc" in traceItem) {
383+
if (this._node._vm.evm.events.listenerCount("step") > 0) {
384+
this._node._vm.evm.events.emit(
385+
"step",
386+
edrTracingStepToMinimalInterpreterStep(traceItem)
387+
);
388+
}
389+
if (this._rawTraceCallbacks.onStep !== undefined) {
390+
await this._rawTraceCallbacks.onStep(traceItem);
391+
}
392+
} else if ("executionResult" in traceItem) {
393+
if (this._node._vm.evm.events.listenerCount("afterMessage") > 0) {
394+
this._node._vm.evm.events.emit(
395+
"afterMessage",
396+
edrTracingMessageResultToMinimalEVMResult(traceItem)
397+
);
398+
}
399+
if (this._rawTraceCallbacks.onAfterMessage !== undefined) {
400+
await this._rawTraceCallbacks.onAfterMessage(
401+
traceItem.executionResult
402+
);
403+
}
404+
} else {
405+
if (this._node._vm.evm.events.listenerCount("beforeMessage") > 0) {
406+
this._node._vm.evm.events.emit(
407+
"beforeMessage",
408+
edrTracingMessageToMinimalMessage(traceItem)
409+
);
410+
}
411+
if (this._rawTraceCallbacks.onBeforeMessage !== undefined) {
412+
await this._rawTraceCallbacks.onBeforeMessage(traceItem);
413+
}
406414
}
407415
}
408416
}

0 commit comments

Comments
 (0)
Please sign in to comment.