KEMBAR78
gh-109870: Combine exec calls in dataclass by ssweber · Pull Request #110186 · python/cpython · GitHub
Skip to content

Conversation

@ssweber
Copy link

@ssweber ssweber commented Oct 1, 2023

As mentioned in the gh issue, this is my attempt to combine the various exec calls (init, repr, eq, etc) into one, resulting in a increasing speedup with each additional exec call avoided. Around 1.1-1.22 speedup.

I don't expect this to be taken as-is. Mainly wanted to get something up so @ericvsmith has something cleaned up to look at.

We return tuple of name, txt, and locals for each fn.

I added including a striped fn name (no `__`) so that dataclass_return_type can be unique for each fn.

Modified the exec section to join the locals back together, and call them all under one __create_fn__
Don't need globals for each now.

Wait to call _recursive_repr on _repr_fn until later
You may want to do something different here. Essentially I ended up inlining the logic (similar to how you do order defs), since we won't be calling the completed fn like before.
@ssweber ssweber requested a review from ericvsmith as a code owner October 1, 2023 17:45
@bedevere-app
Copy link

bedevere-app bot commented Oct 1, 2023

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ssweber
Copy link
Author

ssweber commented Oct 1, 2023

When I have more time this coming week I’ll figure out how to run test_dataclasses.py locally and see if/what I’ve messed up.

@ssweber
Copy link
Author

ssweber commented Oct 15, 2023

Closing this as @ericvsmith has a much better refactored version

@ssweber ssweber closed this Oct 15, 2023
@ssweber ssweber deleted the dataclass_combined_exec branch October 15, 2023 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant