Skip to main content
XmlEssentials is faster than System.Xml in 66 of the 67 like-for-like comparisons on this page, by 3.0× on average, and it allocates 85% less memory on average. This page shows every number, explains what each one measures, names the comparison System.Xml wins, and tells you where XmlEssentials stands against System.Text.Json.

3.0× faster on average

Than System.Xml, across 67 comparisons. The range is 1.1× to 19×, with one exception.

85% less memory

On average. 32 of the 67 comparisons allocate 0 bytes.

104 bytes

To parse a document of any size into a DOM. System.Xml needs 127 KB to 709 KB for the same files.

How to read these tables

Each table compares the same work done by two or three libraries.
  • Time is the mean time for one operation. A microsecond (µs) is 1,000 nanoseconds (ns).
  • Allocated is the managed memory one operation allocates. Less memory means fewer garbage collections under load.
  • Faster is the System.Xml time divided by the XmlEssentials time. “2.4×” means XmlEssentials does the work in well under half the time. It’s computed from the measured times, before they’re rounded for the table.
  • Less memory is how much less XmlEssentials allocates than System.Xml for the same operation. “100%” means XmlEssentials allocates nothing. The cell is empty where System.Xml allocates nothing either, and “more” marks the two rows where XmlEssentials allocates more.
System.Xml is the baseline: XmlReader, XmlWriter, XmlDocument, XDocument, and a cached System.Xml.Serialization.XmlSerializer. System.Text.Json appears beside it as a yardstick for what a modern .NET serializer achieves. It reads and writes JSON, not XML, so it isn’t doing the same job.

Read real documents

The reader walks every token of four real files and keeps whitespace and comments. These files come from other parsers’ test suites, and none of them was written for this library. The few bytes XmlEssentials allocates are per reader, not per token: buffers for decoded values and for documents with more than eight attributes or namespaces on one element. Pass the reader a scratch buffer and all four files read with 0 bytes allocated, in the same time: See Use Utf8XmlReader.

Parse into a DOM

Each library parses the whole file into its read-only document object model. The 104 bytes are the document object. Everything else lives in pooled buffers that go back to the pool when you dispose the document, which is why the number doesn’t grow with the file. System.Xml allocates one object per node.

Write a DOM back out

Each library writes a parsed document to UTF-8.

Small documents

Small payloads show the fixed cost of each API: what you pay before the first byte is read or written. The tiny document is <root id="1"><n>42</n></root>. The catalog has 200 items. System.Xml allocates 7 KB to write a 30-byte document because every XmlWriter starts with its own buffers. A Utf8XmlWriter writes straight into your buffer, and you can reuse one writer with Reset.

Reader: blocks, skipping, and wide elements

System.Xml reads a stream in blocks of its own. XmlEssentials reads 4 KB blocks and carries an XmlReaderState from one to the next, which is where its allocation in the first row comes from. Two more rows show what that costs beside reading the same input whole:

Writer: formatting and large values

Three more rows aren’t paired with a System.Xml row:

Raw XML

WriteRawValue copies XML you already have into the output. By default it checks that the fragment is well formed, and skipInputValidation: true turns the check off. XmlWriter.WriteRaw in System.Xml never checks, so only the second row is a like-for-like comparison, and there System.Xml takes the fragment as a string and transcodes it. Neither row is part of the averages on this page.

Change a document

The mutable tree, XmlNode, is the counterpart of JsonNode. System.Xml has two trees you can change, so each row appears once against XmlDocument and once against XDocument. The catalog has 200 items, and the second pair of rows adds an attribute and a child to every item and writes the result. This table holds the one comparison on the page that System.Xml wins: XDocument parses, changes, and writes the catalog in 0.85× the time XmlEssentials takes. Both of those rows are also the only ones where XmlEssentials allocates more than System.Xml.

Serialize and deserialize

Single values

One value as a whole document, such as <int>12345</int>.

Objects

An order is one flat object with nine properties. A customer is a small graph: two addresses, 20 line items, and four tags. The lists hold 1,000 objects. When XmlEssentials reads objects, the memory it allocates is the objects and strings it gives you back. When it writes into your buffer, it allocates nothing. System.Xml can’t serialize positional records or dictionaries, so these rows have System.Text.Json beside them alone:

Documents shaped for System.Xml

The Bcl preset reads and writes the XML that System.Xml.Serialization.XmlSerializer produces. The feed and the xsi:type rows use shapes that serializer was designed around: prefixed namespaces, and derived types marked with xsi:type.

References, cycles, and discriminators

These features follow System.Text.Json, so it’s the comparison.

Streams of values

SerializeAsyncEnumerable and DeserializeAsyncEnumerable write and read one value at a time. System.Xml has no counterpart, so its figures are for an array read or written whole, and these rows aren’t part of the averages on this page.

Source generation

A source-generated context needs no reflection, which makes it safe for trimming and Native AOT. It has a write fast path, and it reads with the same engine as the reflection resolver. The first call for a type through reflection costs about 0.6 ms while the serializer builds the type info for that type and options instance. Every later call with the same options uses the cached type info. See Reflection vs. source generation. Each generation mode beside the same mode of the System.Text.Json generator:

How XmlEssentials compares with System.Xml

The headline numbers come from every row above that has a System.Xml figure for the same work: 67 comparisons.
  • Speed. XmlEssentials is faster in 66 of them. The average is 3.0×, which is the geometric mean of the Faster column, the right kind of average for ratios. The median is 2.3×. The smallest win is 1.1× and the largest is 19×.
  • Memory. In the 66 comparisons where System.Xml allocates anything, XmlEssentials allocates 85% less on average, which is the mean of the Less memory column over those rows. In 32 of the 67 it allocates 0 bytes. It allocates more in two: the rows that change a tree.
  • By kind of work. Single values are 4.3× to 19× faster, parsing real documents into a DOM is 3.1× to 3.4×, objects are 1.8× to 5.9×, reading real documents is 1.5× to 2.3×, and writing a DOM back out is 1.4× to 1.7×.
What’s counted, so that you can check it:
  • The tree rows count twice, once against XmlDocument and once against XDocument.
  • The raw XML rows and the stream rows aren’t counted, because System.Xml isn’t doing the same work in them.
  • Rows that have no System.Xml figure aren’t counted.

How XmlEssentials compares with System.Text.Json

XmlEssentials has the same API shape as System.Text.Json, so it’s fair to ask whether it has the same speed. For objects, it does. For single values and the mutable tree, it doesn’t. Of the 47 rows above that have a System.Text.Json figure:
  • Ahead in 10. Objects of three derived types (read 100.4 µs against 142.6 µs, write 61.5 µs against 79.8 µs), a stream of 1,000 orders read (340.3 µs against 462.6 µs), and a long text value written in segments are the widest.
  • Level in 19. The difference is inside the measurement error of the run. That covers most of the object rows: a customer, 1,000 orders, objects mapped as attributes, and objects with a decimal amount, read and written.
  • Behind in 18, by 1.15× to 2.1×. The widest gaps are single values (56 ns against 27 ns to read an int), the mutable tree, a dictionary written, and checked raw XML.
  • Equal or lower in memory in 38 of the 47.
XML asks more of a parser than JSON does. <int>1</int> is three tokens, and the name has to match at both ends; in JSON, 1 is one token. A whole XML document for one value also carries more bytes than the JSON for it. So a single XML value can’t be read or written as fast as a JSON one. What you get instead is XML objects at the speed of JSON objects.

How the benchmarks are run

  • BenchmarkDotNet 0.15.8, ShortRun job with the in-process toolchain, .NET 11.0 on x64, Windows 11 on an Intel Core Ultra 9 285K (run under Hyper-V on 2026-11-25). Every table on this page comes from one run of the whole suite: 229 benchmarks.
  • Each library reads the document it wrote itself, and each side keeps the same whitespace and comments.
  • The System.Xml serializer and its reader and writer settings are created once and reused, which is the fastest way to use them. XmlEssentials writers are reused with Reset.
  • The 0 B results are also enforced by unit tests that measure allocated bytes, so they can’t drift without a test failing.
  • The run uses the just-in-time compiler with its defaults. It doesn’t measure a Native AOT build.
  • Times move by 5% to 8% between runs on this machine. Compare the ratios, not the last digit.
Your documents aren’t these documents. The benchmark project is in the repository so that you can add your own payloads and measure them.

Run the benchmarks yourself

1

Clone the repository

2

Run every benchmark

3

Or run one group

The groups are RealDocumentBenchmarks, Utf8XmlReaderBenchmarks, Utf8XmlReaderFlowBenchmarks, Utf8XmlWriterBenchmarks, Utf8XmlWriterStyleBenchmarks, XmlDocumentBenchmarks, XmlNodeBenchmarks, XmlSerializerBenchmarks, XmlSerializerFeatureBenchmarks, XmlSerializerGraphBenchmarks, XmlSerializerObjectBenchmarks, XmlSerializerObjectSequenceBenchmarks, XmlSerializerSequenceBenchmarks, and XmlSerializerSourceGenBenchmarks. Every group has rows on this page.
4

Read the results

BenchmarkDotNet writes a Markdown table for each group to BenchmarkDotNet.Artifacts/results.

See also

Why XmlEssentials?

Where the library comes from and what it replaces.

Quickstart

Install the package and read, write, and serialize your first document.

Reflection vs. source generation

Choose how the serializer learns about your types.

Benchmark source

Every benchmark on this page, ready to run.