-
Notifications
You must be signed in to change notification settings - Fork 59
Make Instruction class immutable #517
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
Conversation
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 like those changes!
Unfortunately, it looks like they are introducing a noticeable performance regression:
https://github.com/dylibso/chicory/actions/runs/10754183983?pr=517
It would be great if you can verify locally if the data is accurate or we are just looking at different machines noise levels.
d0ffa45 to
b40ba24
Compare
|
I missed a critical place in the interpreter that calls |
b40ba24 to
e5850ea
Compare
e5850ea to
c12d39f
Compare
|
This should be fixed now. I added a private |
|
good catch @andreaTP :) |
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 double check and the quick fix @electrum
| var operands = instruction.operands(); | ||
| instance.onExecution(instruction, operands, stack); | ||
| Operands operands = instruction::operand; | ||
| instance.onExecution(instruction, stack); |
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.
nice clean up!
operands was redundant here.
| } | ||
|
|
||
| @FunctionalInterface | ||
| private interface Operands { |
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 like this trick!


This keeps the
long[]to avoid boxing, which might have a performance impact for the interpreter. It also adds a constant for the common case of an empty array, which avoids allocations and reduces memory usage.The extra clone for instructions created during parsing could be eliminated by adding a trusted package-private constructor, but I hope we don't need to optimize to that level.