Skip to content

Comments

perf(python): get object __dict__ for faster field read/write#2003

Merged
pandalee99 merged 3 commits intoapache:mainfrom
chaokunyang:optimize_struct_field_getset
Jan 12, 2025
Merged

perf(python): get object __dict__ for faster field read/write#2003
pandalee99 merged 3 commits intoapache:mainfrom
chaokunyang:optimize_struct_field_getset

Conversation

@chaokunyang
Copy link
Collaborator

@chaokunyang chaokunyang commented Jan 12, 2025

What does this PR do?

This PR extract __dict__ in object when serialize a dataclass without slots for faster attribute set/set by 16%

Related issues

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

For following object:

COMPLEX_OBJECT = ComplexObject1(
    f1=ComplexObject2(f1=True, f2={-1: 2}),
    f2="abc",
    f3=["abc", "abc"],
    f4={1: 2},
    f5=2**7 - 1,
    f6=2**15 - 1,
    f7=2**31 - 1,
    f8=2**63 - 1,
    f9=1.0 / 2,
    f10=1 / 3.0,
    f12=[-1, 4],
)

This PR gives a 16% speed up

@chaokunyang chaokunyang marked this pull request as draft January 12, 2025 05:45
@chaokunyang chaokunyang reopened this Jan 12, 2025
@chaokunyang chaokunyang marked this pull request as ready for review January 12, 2025 07:02
@chaokunyang
Copy link
Collaborator Author

cc @penguin-wwy

Copy link
Contributor

@pandalee99 pandalee99 left a comment

Choose a reason for hiding this comment

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

LGTM,thanks~

@pandalee99 pandalee99 merged commit d49816c into apache:main Jan 12, 2025
39 checks passed
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