-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: optimize with iterators #3652
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
base: main
Are you sure you want to change the base?
Conversation
web3/_utils/abi.py
Outdated
|
||
@curry | ||
def abi_data_tree(types: Sequence[TypeStr], data: Sequence[Any]) -> List[Any]: | ||
def abi_data_tree(types: Sequence[TypeStr], data: Sequence[Any]) -> "map[ABITypedData]": |
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.
idea for more optimization: rip out this func and replace it with a lambda which would have less overhead than using curry
web3/_utils/abi.py
Outdated
[abi_data_tree(types)], | ||
map(data_tree_map, normalizers), | ||
[partial(recursive_map, strip_abi_type)], | ||
return pipe( |
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.
this could be further optimized by caching the pipe per-method as a compose
object
ee5190b
to
11a0672
Compare
This was originally part of my other PR but that is becoming quite cluttered and hard to review so I separated this one out. Previously, the code would create a new dict from `d` one time for each item in the iterable. Now, the code creates just one new dict from `d` at the beginning and uses that same dict to check membership for each item.
What was wrong?
The formatters init quite a few lists each run, and can be made much more efficient using iterators. This PR does so.
I figured this was more important than the logger stuff in my last PR so finished this one up first.
Related to Issue # N/A
Closes # N/A
How was it fixed?
creation of an IteratorProxy class that allows
map
objects to be passed thru the formatters instead of fully materializing a list every step of the wayTodo:
Cute Animal Picture