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

Handler Lifetime #1151

Closed
zombie-einstein opened this issue Mar 5, 2024 · 8 comments
Closed

Handler Lifetime #1151

zombie-einstein opened this issue Mar 5, 2024 · 8 comments

Comments

@zombie-einstein
Copy link
Contributor

zombie-einstein commented Mar 5, 2024

Hi, I'm trying to create a struct with an Evm as a field and then wrap this as a pyclass using pyo3, but classes with lifetime specifiers cannot be used as Pyclasses.

I was curious if you had any thoughts on creating a Handler with no lifetime specifiers, and if this seemed like a sensible thing to do, or if there was some fundamental roadblock you could forsee?

(Not suggesting this as a change to revm, just something I was considering implementing as part of our project to allow implementing a pyclass)

@Rjected
Copy link
Collaborator

Rjected commented Mar 5, 2024

Does Evm<'static> work?

@zombie-einstein
Copy link
Contributor Author

It would, except it then raises issues with sharing objects between threads in Python.

I vaguely recall there was some workaround for this that restricted the usage of the class in Python, but was wondering if there was a relatively quick win by having a handler that fully owns its members (assuming this would be more restrictive in some way, but we could probably live with this given our specific use case).

@zombie-einstein
Copy link
Contributor Author

This thread talks about pyclasses with static lifetimes PyO3/pyo3#502

@Rjected
Copy link
Collaborator

Rjected commented Mar 5, 2024

Yeah, it would be very useful if the lifetime weren't required, for example it could be used as an associated type in a trait without making that associated type a GAT

@rakita
Copy link
Member

rakita commented Mar 6, 2024

I would save a Context and recreate a Handler every time evm is called.

@zombie-einstein
Copy link
Contributor Author

Thanks @rakita, do have a sense of the overhead incurred with this approach? Our simulation use-case tends to include lots of Python loops calling the EVM.

@rakita
Copy link
Member

rakita commented Mar 7, 2024

Thanks @rakita, do have a sense of the overhead incurred with this approach? Our simulation use-case tends to include lots of Python loops calling the EVM.

In comparison with the interpreter loop this shouldn't be noticeable.

Handler is like 20-25 fields that need to be set and copy of 256 size array (instructions).

@zombie-einstein
Copy link
Contributor Author

Great, thanks for your help

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

No branches or pull requests

3 participants