Skip to content

make error "duplicate" cheaper #950

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 1 commit into from
Sep 8, 2023
Merged

Conversation

davidhewitt
Copy link
Contributor

@davidhewitt davidhewitt commented Sep 7, 2023

Change Summary

For #883 - replaces ValLineError::duplicate with ValLineError::into_owned which avoids the need to convert JsonInput to Python data when handling errors.

This is made possible by changing JsonInput to have Arc on the array and object variants. I used SmallVec inside those variants to avoid double-allocating for small lists & maps. Overall this shouldn't impact performance much, ideally will make it a bit tidier in #883.

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

Selected Reviewer: @samuelcolvin

@codecov
Copy link

codecov bot commented Sep 7, 2023

Codecov Report

Merging #950 (d6d4088) into main (6769140) will decrease coverage by 0.03%.
The diff coverage is 89.13%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #950      +/-   ##
==========================================
- Coverage   93.83%   93.80%   -0.03%     
==========================================
  Files         105      105              
  Lines       15469    15468       -1     
  Branches       25       25              
==========================================
- Hits        14515    14510       -5     
- Misses        948      952       +4     
  Partials        6        6              
Files Changed Coverage Δ
src/errors/line_error.rs 88.50% <63.63%> (-3.45%) ⬇️
src/lazy_index_map.rs 94.44% <92.30%> (-2.86%) ⬇️
src/errors/validation_exception.rs 93.68% <100.00%> (ø)
src/input/input_json.rs 91.83% <100.00%> (+0.02%) ⬆️
src/input/parse_json.rs 96.34% <100.00%> (ø)
src/input/return_enums.rs 85.27% <100.00%> (-0.03%) ⬇️
src/validators/function.rs 92.57% <100.00%> (ø)
src/validators/generator.rs 90.66% <100.00%> (ø)
src/validators/json.rs 97.77% <100.00%> (ø)

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 6769140...d6d4088. Read the comment docs.

📢 Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pydantic).

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 7, 2023

CodSpeed Performance Report

Merging #950 will improve performances by 26.67%

Comparing dh/cheap-error-into-owned (d6d4088) with main (6769140)

Summary

🔥 4 improvements
✅ 134 untouched benchmarks

Benchmarks breakdown

Benchmark main dh/cheap-error-into-owned Change
🔥 test_core_json_fs 929.8 µs 797.7 µs +16.56%
🔥 test_list_of_ints_core_json 6.5 ms 5.2 ms +24.63%
🔥 test_set_of_ints_core_json_duplicates 5.5 ms 4.3 ms +26.67%
🔥 test_set_of_ints_core_json 7.3 ms 6.2 ms +18.74%

@davidhewitt
Copy link
Contributor Author

please review

Copy link
Member

@adriangb adriangb left a comment

Choose a reason for hiding this comment

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

No changes to tests and good performance improvement sounds great to me!

@@ -20,8 +22,8 @@ pub enum JsonInput {
Array(JsonArray),
Object(JsonObject),
}
pub type JsonArray = Vec<JsonInput>;
pub type JsonObject = LazyIndexMap<String, JsonInput>;
pub type JsonArray = Arc<SmallVec<[JsonInput; 8]>>;
Copy link
Member

Choose a reason for hiding this comment

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

I assume we can have more than 8 items right? Is 8 just the default that gets allocated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, how smallvec works is you pick a number of entries (in this case 8) which will be stored inline in the struct, and beyond that size it will instead use a heap allocation.

@davidhewitt davidhewitt merged commit f6b14cc into main Sep 8, 2023
@davidhewitt davidhewitt deleted the dh/cheap-error-into-owned branch September 8, 2023 06:00
@davidhewitt davidhewitt mentioned this pull request Sep 18, 2023
4 tasks
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.

3 participants