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 incorrect test for 580 and get rid of allocations in hot path #662

Merged
merged 8 commits into from
Oct 9, 2023

Conversation

Mingun
Copy link
Collaborator

@Mingun Mingun commented Oct 7, 2023

The first commit fixes the mistake I made when fixing #580, that becomes obvious after some refactoring that coming soon for #567.

Deserialization should consume something from deserializer, otherwise an infinity cycle is possible. That is the reason why fixed SeqItemDeserializer::deserialize_newtype_struct taken SimpleTypeDeserializer instead of self. But when I realized that the problem in the test itself, it become obvious that it should take self, as it does in deserialize_option, for example.

Next commits fixes some pinholes and removes allocation on a hot path. It is expected that XML can have many elements and allocating an array just to read one End event after deserializing it is an overkill.

Mingun and others added 8 commits October 7, 2023 23:00
This is useless to implement in actual deserializers, because serde internal deserializers
(used to implement flatten of tagged enums) does not inherit that values. The right way
to change it is to use serde_test::Compact and serde_test::Readable adapters which would
transform every deserializer that can come from actual deserializers
MapValueDeseriaizer and SeqItemDeserializer should emit error on DeEvent::Eof
instead of calling Visitor::visit_none(). We delegate emitting appropriate error
to the Some variant.

The content of deserialize_option! macro was inlined and handling of DeEvent::Eof
was removed from MapValueDeseriaizer and SeqItemDeserializer.

This does not change existing behavior, because Eof in the middle of struct anyway
would be captured by `read_to_end()` call at the end of structure deserialization,
but this change will report an error in appropriate place, which would important
when we implement error position tracking
Each consumer of MapAccess should consume it fully, so in the end `read_to_end`
actually read only one End tag which name already matches the start name, because
we use reader that checks that
If we would need to hook events reading, have a one place for that is preferable
@Mingun Mingun added serde Issues related to mapping from Rust types to XML optimization Issues related to reducing time needed to parse XML or to memory consumption labels Oct 7, 2023
@codecov-commenter
Copy link

Codecov Report

Merging #662 (9e8158c) into master (c79ad58) will increase coverage by 0.03%.
The diff coverage is 84.78%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@            Coverage Diff             @@
##           master     #662      +/-   ##
==========================================
+ Coverage   64.61%   64.64%   +0.03%     
==========================================
  Files          36       36              
  Lines       17294    17291       -3     
==========================================
+ Hits        11174    11178       +4     
+ Misses       6120     6113       -7     
Flag Coverage Δ
unittests 64.64% <84.78%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/de/var.rs 90.62% <100.00%> (ø)
src/de/mod.rs 69.45% <88.46%> (+0.03%) ⬆️
src/de/map.rs 90.72% <71.42%> (+3.52%) ⬆️

@Mingun Mingun merged commit ca1c09a into tafia:master Oct 9, 2023
6 checks passed
@Mingun Mingun deleted the followup-580 branch October 9, 2023 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Issues related to reducing time needed to parse XML or to memory consumption serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants