Skip to content

Conversation

@electrum
Copy link
Collaborator

@electrum electrum commented Sep 7, 2024

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.

Copy link
Collaborator

@andreaTP andreaTP left a 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

Screenshot from 2024-09-09 10-19-00

It would be great if you can verify locally if the data is accurate or we are just looking at different machines noise levels.

@electrum
Copy link
Collaborator Author

electrum commented Sep 9, 2024

I missed a critical place in the interpreter that calls operands() and passes the array to the static methods.

@electrum
Copy link
Collaborator Author

electrum commented Sep 9, 2024

This should be fixed now. I added a private Operands interface in InterpreterMachine that is functionally identical to IntToLongFunction, but makes the code read better (the latter looked ugly).

@electrum
Copy link
Collaborator Author

Screenshot 2024-09-09 at 9 27 41 PM

@electrum electrum requested a review from andreaTP September 10, 2024 04:34
@bhelx
Copy link
Contributor

bhelx commented Sep 10, 2024

good catch @andreaTP :)

Copy link
Collaborator

@andreaTP andreaTP left a 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);
Copy link
Collaborator

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this trick!

@andreaTP andreaTP merged commit ebf4ddf into dylibso:main Sep 10, 2024
13 checks passed
@electrum electrum deleted the instruction branch September 11, 2024 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants