Skip to content

Reuse code objects for similar dataclass definitions #100930

Description

@brandtbucher

A little over a year ago, @dabeaz came up with a cool way of speeding up dataclass creation by avoiding unnecessary exec calls. Essentially, his proof-of-concept dataklasses module caches code objects for methods of "similarly-shaped" dataclasses, and patches them with the correct names:

https://github.com/dabeaz/dataklasses

I have a working prototype of a similar idea for the stdlib dataclasses module over in #92650. It basically doubles the speed of dataclass definitions.

CC @ericvsmith

Linked PRs

Activity

  1. added
    performancePerformance or resource usage
    stdlibStandard Library Python modules in the Lib/ directory
    3.12only security fixes
    on Jan 11, 2023
  2. self-assigned this
    on Jan 11, 2023
  3. ssweber commented on Jul 17, 2023

    @ssweber

    I’ve been looking at dataclasses and this interests me. What would need to happen to take this over the finish-line?

  4. ericvsmith commented on Jul 17, 2023

    @ericvsmith
    Member

    For starters, an analysis of memory usage and cache hit ratio for common dataclass usage patterns.

  5. ssweber commented on Jul 17, 2023

    @ssweber

    Thanks! I’m assuming this would take some legwork, as pyperformance lacks a dataclass benchmark (if that issue is still relevant)?

    I admit to not being super knowledgeable on the subject, but I like digging into topics. I’ll report back when I have more to contribute.

  6. brandtbucher commented on Nov 21, 2023

    @brandtbucher
    MemberAuthor

    Closing in favor of #109870, which is the current direction dataclasses seems to be heading in.

  7. ssweber commented on Nov 25, 2023

    @ssweber

    From my understanding, this could be complementary with the combined exec rework.

    Combined exec speeds up initial creation, this could further speed up creation of subsequent similar dataclasses.

    Maybe once that has landed, we could rework this if there is interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.12only security fixesperformancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directory

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions