-
Notifications
You must be signed in to change notification settings - Fork 654
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
[WIP] Refactor Stack to eliminate mix types #1666
base: main
Are you sure you want to change the base?
Conversation
9943250
to
4ef015f
Compare
4ef015f
to
2358e8b
Compare
dd9c025
to
17d4586
Compare
17d4586
to
16560c9
Compare
@cburgdorf We can see the A better benchmark would be comparing the times taken to run a |
Some Points to Note
|
To do this we should first write the benchmark code against |
I'm still leaning pretty heavily towards just having |
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.
With respect to benchmarking:
Your suggestion about benchmarking these at the Computation
level seems like the right track. As I think you pointed out, the benchmarks in this pull request aren't likely to give us a very good picture of the performance. You might write a small smart contract that does something like the following.
contract TestStack {
function doLotsOfPops() {
uint v = 0
for (uint i=0; i<100; i++) {
v += 100
}
It'll be worth examining the bytecode this produces and writing up some variants that use in-memory variables instead of a constant like 100
. This approach should give you benchmark scripts that better match the real execution environment and which are not tied directly to the Stack
object's API.
@@ -319,7 +323,41 @@ def stack_pop(self, num_items: int=1, type_hint: str=None) -> Any: | |||
Raise `eth.exceptions.InsufficientStack` if there are not enough items on | |||
the stack. | |||
""" | |||
return self._stack.pop(num_items, type_hint) | |||
if num_items == 1: |
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'd like to completely get rid of the type hinting and any conversion between int <-> bytes
in both the Computation
and Stack
APIs, moving all conversion down into the opcode functions themselves.
For example:
Lines 6 to 8 in dfe43ae
def mstore(computation: BaseComputation) -> None: | |
start_position = computation.stack_pop(type_hint=constants.UINT256) | |
value = computation.stack_pop(type_hint=constants.BYTES) |
This would become:
def mstore(computation: BaseComputation) -> None:
start_position = computation.stack_pop(type_hint=constants.UINT256)
raw_value = computation.stack_pop1()
value = int_to_big_endian(raw_value)
...
What was wrong?
As part of Issue #1656
How was it fixed?
The
Stack
now stores only objects of typeint
. It previously also used to storebytes
. Now thebytes
are converted toint
before storing on the stack, and any theStack
issues out the popped elements in the form ofint
. It is expected to convert theintegers
tobytes
at the call site, wherever necessary.Cute Animal Picture