-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] Initial XML support #27
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
base: main
Are you sure you want to change the base?
Conversation
|
Thank you Lukas! I'll study this and get back you you on these questions. Agreed that we need to address the performance regression for sure. |
|
I was able to address the performance regressions by manually implementing @smunini regarding reviewing this, it probably does not make much sense to go through each commits individually. You should focus on the final state. |
|
Thank you Lukas! I should be able to review this PR in the next day or so. |
Hi Steve,
this PR implements full XML support (R4, R4B, R5 and R6 finally roundtrip successfully after a lot of back and forth).
XML vs JSON model
While most of the mediation between the XML and JSON models is handled by dedicated XML serializer and deserializer, I had to make a few changes to the derive macros. This is mostly to reduce some complexity and the need for extensive buffering and reordering of primitive id and extension. Otherwise one would have to translate e.g.
brithDate(XML) tobirthDate,_birthDate(JSON) model, just to have the derived Deserialize impl convert it back to the nestedbirthDate(sturct) element.The
TmpXxxstructs now use to helper enums in theDeserializeimpls:PrimitiveOrElementto be able to handle both thebirthDate,_birthDate(JSON) andbrithDate(XML) natively.SingleOrVecfor sequence fields. This is required because the XML deserializer does not have extensive knowledge of the FHIR model and can thus not know if it needs to callvisit_seqorvisit_xxx(for single-cardinality fields).A potential drawback of this approach, is that the deserializer is more lenient for some invalid JSON inputs. E.g.
”birthDate”: { “value”: “..”, “id”: “..”, “extension”: {..}}although invalid FHIR JSON.Similar for passing single values where a sequence would be expected.
In my opinion this trade off is acceptable, given the extensive discussion about worse tradeoffs we had in #20.
But, please let me know what you think!
JSON Benchmark (no regression)
Unfortunately the above mentioned changes resulted in some significant performance regressions.I will try to investigate and improve on this, but I wanted to share the current state with you.
The current implementation shows almost no regression.
Initially I removed a bunch of JSON skips, that actually seem to work properly.
One of the later commits re-added them to make the numbers across branches comparable. Do you want to keep these skips or shall we drop the commit that reintroduces them again?
serde-supportI added a new helper crate
serde-supportto hold the newPrimitiveOrElementandSingleOrVechelpers.I also moved the preexisting
IdAndExtensionHelpersthere, which were previously generated as nested structs all over again for each individual FHIR struct.This improves the compile time somewhat (almost negligible in my local tests) but the final binary size signficicantly (
test_examplesbinary from > 2GB after addingPrimitiveOrElementandSingleOrVecto 1,23GB; with debug symbols though).We can think about moving the helpers into a private mod within
crate/fhir/src. This would require moving[test_json_serde.rs](http://test_json_serde.rs/)and[test_xml_serde.rs](http://test_xml_serde.rs/)intocrate/fhir/srcthough as these need access to the helpers.Interestingly even with having
[test_json_serde.rs](http://test_json_serde.rs/)and[test_xml_serde.rs](http://test_xml_serde.rs/)incrate/fhir/test, they can still not access private identifiers fromcrate/fhir/src.Let me know which approach you prefer:
serde-support(current state, my 1st choice): Separation of src and tests (in helios-serde); but additional crate not intended for public useserde_supportpackage inhelios-fhir (my last choice): Noisy public API forhelios-fhir`serde_supportpackage inhelios-fhir (my 2nd choice):test_json_serde.rsandtest_xml_serde.rsneed to be moved into thecrates/fhir/src` tree; tests are less separated by concernLeft Todo
Potential future improvements
To the derive macro
serde_json::Value