Skip to content
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

stop clone-ing serializers #1402

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

davidhewitt
Copy link
Contributor

Change Summary

In general, cloning serializers is a potentially expensive runtime operation; we should instead store Arc<CombinedSerializer> and cheaply clone that where needed.

Related issue number

N/A

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Copy link

codecov bot commented Aug 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.53%. Comparing base (ab503cb) to head (99b8e85).
Report is 143 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1402      +/-   ##
==========================================
- Coverage   90.21%   89.53%   -0.69%     
==========================================
  Files         106      109       +3     
  Lines       16339    17345    +1006     
  Branches       36       41       +5     
==========================================
+ Hits        14740    15529     +789     
- Misses       1592     1796     +204     
- Partials        7       20      +13     
Files Coverage Δ
src/serializers/computed_fields.rs 97.84% <ø> (+0.16%) ⬆️
src/serializers/fields.rs 96.29% <ø> (+0.65%) ⬆️
src/serializers/infer.rs 94.06% <100.00%> (-1.06%) ⬇️
src/serializers/shared.rs 79.03% <ø> (-0.19%) ⬇️
src/serializers/type_serializers/any.rs 100.00% <100.00%> (ø)
src/serializers/type_serializers/bytes.rs 100.00% <ø> (ø)
src/serializers/type_serializers/dataclass.rs 85.44% <ø> (+0.61%) ⬆️
src/serializers/type_serializers/datetime_etc.rs 100.00% <ø> (ø)
src/serializers/type_serializers/decimal.rs 95.23% <ø> (ø)
src/serializers/type_serializers/definitions.rs 85.00% <ø> (-15.00%) ⬇️
... and 22 more

... and 34 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd81a75...99b8e85. Read the comment docs.

Copy link

codspeed-hq bot commented Aug 12, 2024

CodSpeed Performance Report

Merging #1402 will not alter performance

Comparing davidhewitt:dh/no-clone-serializers (99b8e85) with main (fd81a75)

Summary

✅ 155 untouched benchmarks

Copy link
Member

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Great! It's cool to learn about new rust concepts through reviewing your PRs.

I'd be happy to open a PR like this tomorrow for validators, if you think that would help as well :).

@sydney-runkle sydney-runkle merged commit 7368c1f into pydantic:main Aug 13, 2024
29 checks passed
@davidhewitt davidhewitt deleted the dh/no-clone-serializers branch August 13, 2024 07:52
@davidhewitt
Copy link
Contributor Author

While the offer is welcome, actually I did a similar change already for validators in 5f14973

Though in the same line, what we should try to work towards is resolving this TODO:

pydantic-core/Cargo.toml

Lines 30 to 32 in 7368c1f

# TODO it would be very nice to remove the "py-clone" feature as it can panic,
# but needs a bit of work to make sure it's not used in the codebase
pyo3 = { version = "0.22.2", features = ["generate-import-lib", "num-bigint", "py-clone"] }

Last I checked the hard bit is that we clone error values; we might be able to restructure errors to remove the need.

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