Skip to content

XML and JSON serializer comparisons#

These tables compare the same inputs and decoded values within each runtime. They show native options, competitor libraries and PolyXML's generated bindings. They do not rank languages against one another. Read and write costs are separate; lower latency is better, and a relative score above 1 means faster than the stated baseline. All results are from PolyXML 0.34.8, October 4, 2026.

The main sensor tables use 1,000 records / 53,795 XML bytes. Every Id and integer Value is checked before timing. Setup and file I/O are excluded; reads construct the complete model, and writes allocate fresh output. The retained samples and all-case summary include single-record and escaped-text cases plus process variation.

What is actually being compared?#

Runtime Native option in this comparison PolyXML path Competitor / baseline Meaning
Rust No stdlib XML binding used; serde_json for JSON Generated XML codec; Serde-derived JSON models quick-xml Serde, serde-xml-rs; handwritten Serde JSON XML binding engines; JSON model overhead
Python ElementTree / json plus handwritten typed mapping Rust-backed binding into generated dataclasses xsdata on the same dataclasses; lxml typed adapter; Pydantic XML reference End-to-end typed binding; specialized adapters labeled separately
Java StAX API; Woodstox provider on this classpath Generated POJOs with direct StAX codec Jackson XML on the same POJOs; XJC-generated JAXB Typed XML binding, on a separate 80-field workload
Go encoding/xml Generated root model and native serializer Flat handwritten struct and same native serializer Generated model / root-method overhead
C# XmlSerializer Generated inherited classes and native serializer Flat handwritten class and same native serializer Generated model overhead under an explicit JIT configuration
C++ Existing C ABI binding Native value graph mapped into models Equivalent competitor not measured here Coverage gap; narrow string-search adapter excluded
TypeScript / Wasm Existing JS object parsers Wasm binding Equivalent typed return graph not measured here Coverage gap; existing parser studies remain separate

Rust XML: generated codecs versus Serde adapters#

Source, generated models and dependency lock, raw summary. Both the generated codecs and quick-xml's Serde adapter use quick-xml 0.42.0; this compares their binding code, not different tokenizers. Ratios use quick-xml Serde with the same string ownership as the row.

Serializer / model Read µs ↓ Write µs ↓ Read relative ↑ Write relative ↑
PolyXML generated · String 232.13 54.05 1.88× 3.68×
quick-xml Serde · String 436.12 198.84 1.00× 1.00×
serde-xml-rs · String 2407.85 323.46 0.18× 0.61×
PolyXML generated · Cow 191.62 54.51 2.13× 3.64×
quick-xml Serde · Cow 409.00 198.32 1.00× 1.00×

The generated owned codec takes about half the read time of quick-xml Serde, and its writer takes roughly a quarter of the time on this fixture. Borrowed XML avoids string copies for plain text; escaping can require owned strings. Both Cow readers are checked to actually borrow on the plain fixture. See quick-xml's borrowing rules.

The dynamic Rust engine returns a PolyValue record/list graph rather than the typed structs above. Its separate reference result is:

Value representation Read µs ↓ Write µs ↓
PolyXML dynamic · PolyValue 638.54 89.68

Rust allocation diagnostics#

Separate instrumented output. These are total requested allocation bytes and allocation/reallocation calls per operation, not peak RAM or retained memory. Timings above come from a separate binary without the allocation counter.

Serializer / model Read requested B Write requested B Read calls Write calls
PolyXML generated · String 83,354 141,064 2,012 1,014
quick-xml Serde · String 75,607 449,272 1,016 4,016
serde-xml-rs · String 6,913,011 175,329 49,040 9,020
PolyXML generated · Cow 65,464 141,064 12 1,014
quick-xml Serde · Cow 65,717 449,272 16 4,016
PolyXML dynamic · different value graph 471,402 130,560 3,024 8

Python XML: complete typed results#

Same-run samples and source. PolyXML and xsdata construct the same generated slotted dataclasses. The stdlib and lxml adapters construct those same models and convert integers inside timing; they are not DOM-only parser timings. Ratios use xsdata.

Serializer / model Read µs ↓ Write µs ↓ Read relative ↑ Write relative ↑
PolyXML · generated dataclasses 1622.47 767.10 8.67× 18.53×
xsdata · same dataclasses 14064.81 14211.82 1.00× 1.00×
stdlib ElementTree · typed adapter¹ 1155.20 3220.89 12.18× 4.41×
lxml · typed adapter¹ 3452.17 1615.67 4.07× 8.80×

¹ These handwritten adapters are specialized to this two-field schema. They are useful native baselines, but do not implement a general schema-driven binder. ElementTree's adapter reads this batch faster than PolyXML; PolyXML writes it faster. That distinction matters alongside the larger gains over xsdata.

Pydantic XML builds a different, validating model graph. Keep it as a reference rather than treating it as the same dataclass task:

Reference representation Read µs ↓ Write µs ↓
pydantic-xml · Pydantic v2 models 8866.62 7744.33

Python timings use a release native extension, without tracemalloc. The old traced Python measurements are not mixed into this table. We do not report Python-only traced bytes as total Rust/libxml2 allocation.

JSON: separate from XML#

All JSON samples, source and allocation diagnostics. The plain 1,000-sensor JSON input is identical within each runtime; all writers are checked against the same JSON values.

Rust JSON: the same serde_json engine#

Generated Rust JSON models and handwritten models all use serde_json 1.0.151. These rows measure model choices, not a separate PolyXML JSON engine. The generated Cow JSON model does not carry field-level Serde borrowing annotations; its strings deserialize as owned. The XML borrowing result above does not apply.

Model / serde_json Read µs ↓ Write µs ↓
PolyXML-generated · String 64.03 26.95
PolyXML-generated · Cow 61.69 26.87
Handwritten Serde · String 62.26 27.16

Python JSON: typed dataclasses#

Ratios use xsdata JSON. The stdlib adapter includes JSON parsing and complete model construction, or model-to-dict conversion and UTF-8 output, inside timing.

Serializer / model Read µs ↓ Write µs ↓ Read relative ↑ Write relative ↑
PolyXML · generated dataclasses 1381.68 786.60 7.04× 4.60×
xsdata · same dataclasses 9730.96 3619.62 1.00× 1.00×
stdlib json · specialized typed adapter 408.83 272.63 23.80× 13.28×

PolyXML is faster than xsdata here, while the specialized stdlib adapter is faster than both. This fixture does not justify claiming PolyXML is the fastest Python JSON serializer.

Go and C#: generated models using native XML serializers#

All native-model samples, sources and runtime settings, computed summary. These are model comparisons using the same serializer in each language. Readers use the shared sensor fixture; writers produce equivalent sensor values. Go writes UTF-8 bytes, while C# writes a materialized UTF-16 string. Compare within each runtime, not between these rows. Allocations are Go's benchmem bytes/op or .NET's current-thread managed bytes/op.

Runtime / model Read µs ↓ Write µs ↓ Read allocated B Write allocated B
Go · encoding/xml · generated 2031.08 486.73 1,035,712 266,641
Go · encoding/xml · handwritten 1961.18 423.01 1,035,648 134,608
C# · XmlSerializer · generated 621.47 513.28 147,520 330,120
C# · XmlSerializer · handwritten 611.52 513.22 147,568 330,120

Go's generated root type has custom MarshalXML/UnmarshalXML methods for root naming and namespace checks. The flat handwritten baseline lacks those methods. The custom root writer adds allocations and timing overhead in this comparison.

C# uses .NET 10.0.12, with the net8.0 build rolled forward. The published control sets DOTNET_TieredCompilation=0, excludes serializer construction, and warms each model for at least two seconds / 500 read-write pairs. This is an explicit warmed JIT configuration, not default startup/tiered-PGO behavior. The default-tiering diagnostics and control settings are retained: their first-model effect persisted despite longer warmup, so they are not used to rank models. See the .NET compilation settings.

Java XML: direct StAX, Jackson and JAXB#

Raw JMH JSON, including every fork, score error and GC metric, fixture/output lengths and execution log. Java uses its own 80-field synthetic projections, with seven populated string fields and 73 absent optional fields. Each operation processes 1,000 independent messages. These are not official ISO/UCI documents and are not the sensor workload. Read IDs vary; writes serialize the preconstructed ID-0 model to fresh bytes 1,000 times. Setup checks every input across typed readers.

The recorded StAX providers are Woodstox 7.1.1 on this shaded classpath. The direct codec uses the JDK StAX API with that provider; this is not a claim about the JDK's default XML parser.

Numbers are batches/s, with JMH's reported score error; higher is better. Direct StAX and Jackson populate the same generated POJOs. JAXB populates the equivalent XJC models. Panama's different native return graph is excluded.

Workload / typed binding Read batches/s ↑ Write batches/s ↑ Read heap B/message Write heap B/message
Settlement · PolyXML direct StAX 380.1 ± 4.8 208.1 ± 4.3 4,520 9,456
Settlement · Jackson XML 402.5 ± 4.9 197.9 ± 1.7 5,040 6,584
Settlement · JAXB / XJC 173.6 ± 3.3 127.0 ± 1.3 7,096 28,608
Telemetry · PolyXML direct StAX 605.3 ± 2.5 698.9 ± 4.6 2,720 5,856
Telemetry · Jackson XML 626.0 ± 4.4 490.1 ± 3.6 3,240 1,728
Telemetry · JAXB / XJC 238.8 ± 1.7 248.8 ± 6.9 3,496 7,328

Output lengths differ because serializers emit different declarations and namespace formatting; the log records them. Overlapping JMH errors do not establish a winner. GC metrics cover the Java heap.

Small inputs and escaped text#

The complete summary retains all lanes. The compact checks below show that the relative result changes with input size and escaping. Same timing method and ownership-matched baselines as the main Rust table.

Rust · one sensor (65 B XML)#

Serializer / model Read µs ↓ Write µs ↓ Read relative ↑ Write relative ↑
PolyXML generated · String 0.32 0.19 2.33× 2.22×
quick-xml Serde · String 0.74 0.42 1.00× 1.00×
serde-xml-rs · String 3.46 0.71 0.21× 0.59×
PolyXML generated · Cow 0.30 0.19 2.47× 2.20×
quick-xml Serde · Cow 0.74 0.41 1.00× 1.00×

Rust · 1,000 sensors with entities, quotes and UTF-8#

Serializer / model Read µs ↓ Write µs ↓ Read relative ↑ Write relative ↑
PolyXML generated · String 379.10 133.96 1.71× 1.84×
quick-xml Serde · String 649.90 247.09 1.00× 1.00×
serde-xml-rs · String 2926.95 365.01 0.22× 0.68×
PolyXML generated · Cow 363.82 133.71 1.78× 1.71×
quick-xml Serde · Cow 646.78 228.38 1.00× 1.00×

For Python, the all-case summary includes the same single-record and escaped-text fixtures. Native call overhead, model construction and escaping matter differently at each size; the main 1,000-record ratio should not be applied to every XML document.

Environment, variation and reproduction#

Exact metadata, hashes and dependency versions, native-model toolchains and settings, reproducible suite. The engine/compiler source is release 0.34.8 / 89786c3. Harness revisions and generated-source hashes are recorded separately in the artifacts.

Item Configuration
Host Intel Core i5-11600K, 6 cores / 12 logical CPUs; WSL2, Ubuntu 26.04.1; 15.5 GiB visible RAM
Rust rustc/cargo 1.99.0; release; quick-xml 0.42.0, serde-xml-rs 0.8.2, Serde 1.0.229, serde_json 1.0.151
Python CPython 3.12.15; release ABI3 extension; xsdata 26.2, lxml 6.1.3, pydantic-xml 2.21.1, Pydantic 2.13.5
Go / .NET Go 1.26.0; .NET SDK 10.0.112 / runtime 10.0.12; C# control disables tiered compilation
Java JDK 25.0.4.1; JMH 1.37; Jackson XML 2.21.2; JAXB 4.0.5; two forks, three 2-second warmups, five 2-second measurements; 256 MiB initial / 1 GiB max heap
Scheduling Builds and timings serial; model/case order rotated; memory-capped processes; IDE background services present; no CPU affinity/frequency control

Rust/Python use six independent processes, each with five samples of at least 150 ms per operation after warmup. Tables report the median of process medians. All process ranges are descriptive minimum–maximum ranges, not confidence intervals. Samples within a process are correlated. Go uses five fresh processes / 2-second bench windows; C# control uses six fresh processes / 1,000 calls per operation, with first-model order balanced. Their process ranges are also retained. Java reports JMH throughput and its own score error rather than these medians.

Every reader field and writer value is checked outside timing. Python XML outputs pass XSD validation through lxml; all 33 exported Rust/Python XML outputs are checked again using independent stdlib ElementTree parsing. JSON outputs are compared as complete values. Writer byte lengths are retained in the raw CSVs. This is a performance comparison of these valid fixtures, not a conformance score or a full-schema-validation timing.

September results remain historical; they use a different host/version and are not blended with these figures. C++ and TypeScript need equivalent return graphs and repeated matched measurements before joining this typed comparison. Existing C++ native results and Wasm parser studies retain their own scope.