This repository was archived by the owner on Sep 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 695
[WIP] Refactor Stack to eliminate mix types #1666
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| import time | ||
|
|
||
| from eth.vm.stack import ( | ||
| Stack, | ||
| Stack_Old, | ||
| ) | ||
|
|
||
|
|
||
| def push_benchmark(): | ||
| stack = Stack() | ||
| uint_max = 2**32 - 1 | ||
|
|
||
| start_time = time.perf_counter() | ||
| for _ in range(500): | ||
| stack.push(uint_max) | ||
| stack.push(b'\x00' * 32) | ||
| time_taken_refactored = time.perf_counter() - start_time | ||
|
|
||
| stack_old = Stack_Old() | ||
| start_time = time.perf_counter() | ||
| for _ in range(500): | ||
| stack_old.push(uint_max) | ||
| stack_old.push(b'\x00' * 32) | ||
| time_taken_old = time.perf_counter() - start_time | ||
|
|
||
| return time_taken_refactored, time_taken_old | ||
|
|
||
|
|
||
| def pop_benchmark1(): | ||
| # This is a case which favours the new built Stack | ||
| stack = Stack() | ||
| stack_old = Stack_Old() | ||
|
|
||
| for stack_obj in (stack, stack_old): | ||
| for _ in range(1000): | ||
| stack_obj.push(b'\x00' * 32) | ||
|
|
||
| start_time = time.perf_counter() | ||
| stack.pop_n(1000) | ||
| time_taken_refactored = time.perf_counter() - start_time | ||
|
|
||
| start_time = time.perf_counter() | ||
| stack_old.pop(1000, "uint256") | ||
| time_taken_old = time.perf_counter() - start_time | ||
|
|
||
| return time_taken_refactored, time_taken_old | ||
|
|
||
|
|
||
| def pop_benchmark2(): | ||
| # This is a case which favours the old Stack | ||
| stack = Stack() | ||
| stack_old = Stack_Old() | ||
|
|
||
| for stack_obj in (stack, stack_old): | ||
| for _ in range(1000): | ||
| stack_obj.push(b'\x00' * 32) | ||
|
|
||
| start_time = time.perf_counter() | ||
| stack.pop_n(1000) | ||
| time_taken_refactored = time.perf_counter() - start_time | ||
|
|
||
| start_time = time.perf_counter() | ||
| stack_old.pop(1000, "bytes") | ||
| time_taken_old = time.perf_counter() - start_time | ||
|
|
||
| return time_taken_refactored, time_taken_old | ||
|
|
||
|
|
||
| #push_benchmark() | ||
| #pop_benchmark1() | ||
| #pop_benchmark2() | ||
|
|
||
| def main(): | ||
| print("Stack Push of 500 bytestrings and 500 integers") | ||
| print("----------------------------------------------") | ||
| refactored_time, old_time = push_benchmark() | ||
| print("Old Code\t\t|\t{}".format(old_time)) | ||
| print("Refactored Code\t\t|\t{}".format(refactored_time)) | ||
| print("\n\n") | ||
|
|
||
| print("Stack Pop 1000 times (Pushed 1000 bytestrings)(For old one, expected popped output in int)") | ||
| print("----------------------------------------------") | ||
| refactored_time, old_time = pop_benchmark1() | ||
| print("Old Code\t\t|\t{}".format(old_time)) | ||
| print("Refactored Code\t\t|\t{}".format(refactored_time)) | ||
| print("\n\n") | ||
|
|
||
| print("Stack Pop 1000 times (Pushed 1000 bytestrings)(For old one, expected popped output in bytes)") | ||
| print("----------------------------------------------") | ||
| refactored_time, old_time = pop_benchmark2() | ||
| print("Old Code\t\t|\t{}".format(old_time)) | ||
| print("Refactored Code\t\t|\t{}".format(refactored_time)) | ||
|
|
||
|
|
||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 <-> bytesin both theComputationandStackAPIs, moving all conversion down into the opcode functions themselves.For example:
py-evm/eth/vm/logic/memory.py
Lines 6 to 8 in dfe43ae
This would become: