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

fix with python parsing seen on pydantic-core #54

Merged
merged 4 commits into from
Jan 17, 2024
Merged

Conversation

samuelcolvin
Copy link
Member

This was introduced by #48 (I checked the commit before and tests passed, failed after).

Honestly I'm not sure about this implementation of Peek, it means no compiler error or warning if you miss cases in a match statement.

Maybe we can someone combine storing the raw u8 with an enum @davidhewitt?

@@ -117,16 +127,6 @@ impl<'j> PythonParser<'j> {
}
Ok(dict.to_object(py))
}
_ => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, removing this clause did cause errors to fire here about non-exhaustive matching 😉. But I take your point about it not enforcing all datatypes.

I think part of the performance win in #48 was that it effectively removed a large set of branches (from Peak::new) because we have these same set of branches anyway when we decide what to do with the peek's u8. Put another way, we assume that the peek is always valid and defer erroring until after we fail to parse an integer.

It's definitely possible that there's another way to express this which keeps the same performance property, might require a play and a think.

src/python.rs Outdated
Peek::Minus | Peek::Infinity | Peek::NaN => {
let n = self
.parser
.consume_number::<NumberAny>(peek.into_inner(), self.allow_inf_nan)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe one solution is to remove peek.into_inner() and replace it with peek.into_number() which errors when it's not a number? This would probably keep most of the same performance properties, but force you to handle all invalid cases earlier as part of the wildcard / numerical branch.

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

Merging #54 (9479c07) into main (849d5b8) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #54      +/-   ##
==========================================
+ Coverage   93.03%   93.06%   +0.02%     
==========================================
  Files           8        8              
  Lines        1048     1052       +4     
==========================================
+ Hits          975      979       +4     
  Misses         73       73              
Files Coverage Δ
src/python.rs 93.69% <100.00%> (+0.23%) ⬆️

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 849d5b8...9479c07. Read the comment docs.

Copy link

codspeed-hq bot commented Jan 17, 2024

CodSpeed Performance Report

Merging #54 will not alter performance

Comparing fix-python-error (9479c07) with main (849d5b8)

Summary

✅ 39 untouched benchmarks

Copy link
Collaborator

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +62 to +65
Peek::Null => {
self.parser.consume_null()?;
Ok(py.None())
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

For what it's worth the compiler will probably reorder branches in a match for what it thinks makes most sense anyway (as long as they're not gated by conditionals, only one of these branches will be traversed), so moving this likely does nothing.

@davidhewitt davidhewitt merged commit 1ce40b3 into main Jan 17, 2024
10 checks passed
@davidhewitt davidhewitt deleted the fix-python-error branch January 17, 2024 10:39
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