Skip to content

feat: optimize apply_abi_formatters_to_dict #3671

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

Merged
merged 3 commits into from
Apr 21, 2025

Conversation

BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Apr 17, 2025

What was wrong?

nothing was wrong, but apply_abi_formatters_to_dict is used frequently so was suitable for optimization

Related to Issue #N/A
Closes #N/A

Todo:

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

formatted_dict = dict(zip(fields, formatted_values))
return dict(data, **formatted_dict)
formatted_dict = data.copy()
formatted_dict.update(zip(fields, formatted_values))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of fully initializing a formatted_dict and then initializing a second new dict with it, we can just init one copy of the original dict and update it from a zip

@BobTheBuidler
Copy link
Contributor Author

Now that you've merged #3665 and #3666 I rebased my branch on master and reran the tests, looks like everything passes now

[abi_dict[field] for field in fields],
[data[field] for field in fields],
(abi_dict[field] for field in fields),
(data[field] for field in fields),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

2 less list creations per call

Copy link
Contributor

@pacrob pacrob left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @BobTheBuidler!

@pacrob pacrob merged commit aff163c into ethereum:main Apr 21, 2025
85 checks passed
@BobTheBuidler BobTheBuidler deleted the formatters branch April 22, 2025 16:59
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