4 ms·
I have some experience with libxml2. I would say DOM parsing is partly inefficient due to the many small allocations, and the library does not offer fine graine
by planede 4y ago
I have some experience with libxml2. I would say DOM parsing is partly inefficient due to the many small allocations, and the library does not offer fine grained control over it. The allocator is globally replaceable, but that's not very flexible.
I wished many times if I could just use an arena with a dumb allocator for a small document and just drop it when I finish with the document, but it's not very easy to do with libxml2, unless you write your own DOM parser on top of SAX.
- sgerenser 4y agoI’ve made good use of PugiXML: https://pugixml.org/ https://pugixml.org/. Faster than most SAX parsers with the simpler interface of DOM. Gets around the small allocation problem by making a mutable copy of the entire input, then modifying it in place, and only allocating (using arenas) when absolutely necessary. C++ though so not very easy to use from other languages like libxml2 is.
- planede 4y agoIt looks interesting, but it looks like it has no or limited XML namespace support, which is a shame.
- zaphar 4y agoProbably true but also DOM parsing is usually not necessary and streaming parsing is not that hard so why not just skip the DOM and go straight to streaming instead?
- planede 4y agoDOM parsing is not necessary until it is. Sometimes you can get away with parsing the stream twice and still beat DOM parsing, but not always. Stream parsing is indeed preferable when you can get away with it.