Skip to content
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

Smol optimizations #166

Merged
merged 6 commits into from
Aug 11, 2023
Merged

Smol optimizations #166

merged 6 commits into from
Aug 11, 2023

Conversation

karmacoma-eth
Copy link
Collaborator

2 things:

  • cache the BitVecSort(n) invocations, which we do a lot of
  • work with the natural stack/list ordering

Saves about 10% on some path-intensive benchmark (172M -> 156M function calls), coming mostly from caching

i.e. push and pop at the end of the list instead of at the beginning
BitVecSort256 = BitVecSorts[256]
BitVecSort264 = BitVecSorts[264]
BitVecSort512 = BitVecSorts[512]

Copy link
Collaborator

@daejunpark daejunpark Aug 10, 2023

Choose a reason for hiding this comment

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

Q: could you help me understand the behavior of this global mutable object when multiple SEVM objects are created?

for example, say we have two sevm objects:

from halmos.sevm import SEVM

sevm1 = SEVM(options)
sevm2 = SEVM(options)

will they have the same cache object, or a different one?

if the former, would it be safe when we run sevm1 and sevm2 in parallel in a thread or process pool?

in any case, can we avoid the use of global mutable objects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you're right I didn't think of that, both instances would access the same object because it's at the module level. I can make it read only to avoid this issue

this means that not every BitVecSort will be cached, only the ones deemed most common during initialization
@karmacoma-eth
Copy link
Collaborator Author

I think the CI failures are now due to farcaster being in a bad state (farcasterxyz/contracts#275 (comment)), unrelated to the changes in this PR

@daejunpark
Copy link
Collaborator

yes, i know that. cicada test was canceled because of that. i set fail-fast false, so that we can make sure that all but farcaster test succeed. let's merge after we confirm that.

@karmacoma-eth karmacoma-eth merged commit 1524d20 into main Aug 11, 2023
90 of 91 checks passed
@karmacoma-eth karmacoma-eth deleted the smol-optimizations branch August 11, 2023 01:15
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.

2 participants