-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve flat trace generation performance #6472
Improve flat trace generation performance #6472
Conversation
Signed-off-by: Ameziane H <[email protected]>
|
.../hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/flat/FlatTraceGenerator.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Ameziane H <[email protected]>
Signed-off-by: Ameziane H <[email protected]>
Signed-off-by: Ameziane H <[email protected]>
… into improve-trace-block-on-subcalls
Signed-off-by: Ameziane H <[email protected]>
Signed-off-by: Ameziane H <[email protected]>
… into improve-trace-block-on-subcalls
Signed-off-by: ahamlat <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OPCODE request is optional.
if (i + 1 < transactionTrace.getTraceFrames().size()) { | ||
final TraceFrame next = transactionTrace.getTraceFrames().get(i + 1); | ||
if (next.getDepth() == callFrame.getDepth()) { | ||
if (next.getOpcodeNumber() == 0xFD) { // REVERT opCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding an OPCODE constant to RevertOperation and ReturnOperation so we can reduce magic constants in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, I was thinking actually of an Enum OpCode to store all the opcodes and use only the Enum in the EVM and outside, like Opcode.REVERT.getOpcodeNumber() for 0xFD
public enum Opcode {
STOP(0x00, "STOP"),
ADD(0x01, "ADD"),
MUL(0x02, "MUL"),
...
}
In terms of performance, I guess JIT will replace by the opCodeNumber or the opcode name at runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shemnon I've added the OpCode enum within the EVM and would like to use it across all EVM opcode operations. An implementation example has been provided for ADDMOD. Does this approach work for you ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not what I meant. Such an OpCode enum breaks extensibility to downstream users use. Please revert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I intended was something like this, where a constant is added to the Operation classes, not an entirely different enum.
public static final int OPCODE = 0x49; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually understood your suggestion but wanted to suggest an implementation that would work for similar use cases in the future, but it looks like it wasn't a good idea. I'm going to revert the last changes.
Signed-off-by: Ameziane H <[email protected]>
Signed-off-by: Ameziane H <[email protected]>
Signed-off-by: Ameziane H <[email protected]>
…eration Signed-off-by: Ameziane H <[email protected]>
@shemnon Could you review the last changes ? |
if (i + 1 < transactionTrace.getTraceFrames().size()) { | ||
final TraceFrame next = transactionTrace.getTraceFrames().get(i + 1); | ||
if (next.getDepth() == callFrame.getDepth()) { | ||
if (next.getOpcodeNumber() == 0xFD) { // REVERT opCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth making AbstractOperation.getOpcode() static and doing the comparison to that to avoid creating another range of enums.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit is outdated. Making AbstractOperation.getOpcode() static means that we need to make opcode static in AbstractOperation which is not the case, opcode depends on the implementation.
What suggested by Danno is very similar in some way to what you suggest, add a static constants directly in the implementation, that is stored in the opcode field.
Improve flat trace generation performance Signed-off-by: Ameziane H <[email protected]>
.filter(traceFrame -> traceFrame.getOpcode().equals("REVERT")) | ||
.anyMatch(traceFrame -> traceFrame.getDepth() == callFrame.getDepth()); | ||
for (int i = 0; i < transactionTrace.getTraceFrames().size(); i++) { | ||
if (i + 1 < transactionTrace.getTraceFrames().size()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of a random question (Side note: I dont really have Java exp) but what is the point of this If condition? Wouldn't starting the loop at 1 and running it until size() - 1
have the same result? (Or if iterating in reverse has no side-effects, even starting at size() - 1 and running while its > 0)
PR description
When testing one of the blocks that has a lot of subcalls (838 internal transactions), we noticed that most of the time was spent on hasRevertInSubCall method.
This PR reduced the time to trace a 29 mgas block from more than 5 seconds to 1 second.
Fixed Issue(s)