|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | +<title>CSS4J DOM benchmarks</title> |
| 5 | +<link href="basic-b.css" rel="stylesheet" type="text/css" /> |
| 6 | +<meta http-equiv="content-type" content="text/html; charset=utf-8"> |
| 7 | +<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 8 | +</head> |
| 9 | +<body id="dom-mark"> |
| 10 | +<div class="layout"> |
| 11 | +<div id="hdr01"></div> |
| 12 | +<a id="mylinkhome" href="/"><span>CSS4J</span></a> |
| 13 | +</div> |
| 14 | +<div class="container"> |
| 15 | +<div class="menu"> |
| 16 | +<ul class="menulist"> |
| 17 | +<li><a id="mnuindice" href="/"><span>Home</span></a></li> |
| 18 | +<li><a id="mnuusage" href="usage.html"><span>Usage</span></a></li> |
| 19 | +<li><a id="mnuapi2" href="api/3/"><span>API 3.x</span></a></li> |
| 20 | +<li><a id="mnufaq" href="faq.html"><span>FAQ</span></a></li> |
| 21 | +<li><a id="mnubenchmarks" href="benchmarks.html"><span>Benchmarks</span></a></li> |
| 22 | +<li class="menulvl2"><div id="mnudommark-sel"><span>DOM mark</span></div></li> |
| 23 | +<li class="menulvl2"><a id="mnusacmark" href="sac-mark.html"><span>SAC mark</span></a></li> |
| 24 | +<li><a id="mnugithub" href="https://github.com/css4j"><span>Github</span></a></li> |
| 25 | +</ul> |
| 26 | +</div> |
| 27 | +<div class="beforemain"></div> |
| 28 | +<div class="main"> |
| 29 | +<div id="presentacion_top" class="textheader"><span>DOM mark</span></div> |
| 30 | +<div class="cos"> |
| 31 | +<h1>DOM benchmarks</h1> |
| 32 | +<div class="tema" id="overview"> |
| 33 | +<h2>Overview</h2> |
| 34 | +<p>The DOM benchmarks measure how fast different DOM implementations are when building documents. The following software versions were used:</p> |
| 35 | +<ul> |
| 36 | +<li>Java: <a href="https://adoptopenjdk.net/">AdoptOpenJDK</a>* 15.</li> |
| 37 | +<li>JMH: 1.26.</li> |
| 38 | +<li>css4j: 3.2 (pre-release).</li> |
| 39 | +<li>validator.nu htmlparser: <a href="https://search.maven.org/artifact/nu.validator/htmlparser">1.4.16</a>.</li> |
| 40 | +</ul> |
| 41 | +<p>The computer has an Intel® Core™ i5-1035G7 CPU and 8GB of RAM.</p> |
| 42 | +<p class="note">(*) Note: one of the tested DOM implementations is the one that comes bundled with the JDK (identified as "JDK" in the graphics), and it has been observed |
| 43 | +that the version shipped with the Oracle JDK may be faster.</p> |
| 44 | +</div> |
| 45 | +<div class="tema" id="html-mark"> |
| 46 | +<h2>Build HTML documents</h2> |
| 47 | +<p>Measures the speed at which the <a href="https://about.validator.nu/htmlparser/">validator.nu HTML parser</a> can build a small document (38 KB HTML) into a few DOM implementations.</p> |
| 48 | +<img src="benchmark/html-build.png" alt="HTML build benchmark" /> |
| 49 | +<p>Numeric results (higher is better):</p> |
| 50 | +<table class="normaltbl"> |
| 51 | +<tr><th>Implementation</th><th>Score</th><th>Error</th><th>Unit</th></tr> |
| 52 | +<tr><td>Css4j-DOM4J</td><td class="number">335,609</td><td class="number">±9,416</td><td>ops/s</td></tr> |
| 53 | +<tr><td>Css4j DOM</td><td class="number">328,637</td><td class="number">±1,920</td><td>ops/s</td></tr> |
| 54 | +<tr><td>JDK</td><td class="number">333,742</td><td class="number">±3,079</td><td>ops/s</td></tr> |
| 55 | +</table> |
| 56 | +<p>If one looks at the error figures, the three implementations are somewhat even in this test.</p> |
| 57 | +</div> |
| 58 | +<div class="tema" id="xml-small-mark"> |
| 59 | +<h2>Build small XML documents</h2> |
| 60 | +<p>The SAX parser that comes bundled with the JDK is used to parse and build a document from a small XHTML file (38 KB).</p> |
| 61 | +<img src="benchmark/xml-build-small.png" alt="XML build benchmark (small file)" /> |
| 62 | +<p>Numeric results (higher is better):</p> |
| 63 | +<table class="normaltbl"> |
| 64 | +<tr><th>Implementation</th><th>Score</th><th>Error</th><th>Unit</th></tr> |
| 65 | +<tr><td>Css4j-DOM4J</td><td class="number">496,924</td><td class="number">±3,864</td><td>ops/s</td></tr> |
| 66 | +<tr><td>Css4j DOM</td><td class="number">447,644</td><td class="number">±7,290</td><td>ops/s</td></tr> |
| 67 | +<tr><td>DOM4J</td><td class="number">520,322</td><td class="number">±1,193</td><td>ops/s</td></tr> |
| 68 | +<tr><td>JDK</td><td class="number">507,176</td><td class="number">±6,105</td><td>ops/s</td></tr> |
| 69 | +</table> |
| 70 | +</div> |
| 71 | +<div class="tema" id="xml-small-mark"> |
| 72 | +<h2>Build XML documents</h2> |
| 73 | +<p>The SAX parser that comes bundled with the JDK is used to parse and build a document (1MB file).</p> |
| 74 | +<img src="benchmark/xml-build.png" alt="XML build benchmark" /> |
| 75 | +<p>Numeric results (higher is better):</p> |
| 76 | +<table class="normaltbl"> |
| 77 | +<tr><th>Implementation</th><th>Score</th><th>Error</th><th>Unit</th></tr> |
| 78 | +<tr><td>Css4j-DOM4J</td><td class="number">92,285</td><td class="number">±3,441</td><td>ops/s</td></tr> |
| 79 | +<tr><td>Css4j DOM</td><td class="number">76,500</td><td class="number">±0,630</td><td>ops/s</td></tr> |
| 80 | +<tr><td>DOM4J</td><td class="number">106,743</td><td class="number">±0,852</td><td>ops/s</td></tr> |
| 81 | +<tr><td>JDK</td><td class="number">113,399</td><td class="number">±1,531</td><td>ops/s</td></tr> |
| 82 | +</table> |
| 83 | +</div> |
| 84 | +<div class="tema" id="analysis"> |
| 85 | +<h2>Analysis</h2> |
| 86 | +<p>DOM4J (both plain DOM4J and the CSS-enabled subclasses that CSS4J provide) is fast, but has an important scalability problem. If you use |
| 87 | +instances of DOM4J simultaneously in the same JVM, contention happens even if no common resources are explicitly accessed. This is due to DOM4J using a <code>static</code> synchronized cache of <code>QName</code> objects, |
| 88 | +as shown by the benchmark profiler (e.g. <code>java -jar build/benchmarks.jar XMLBuildBenchmark -prof stack:lines=5;top=3;detailLine=true;period=1</code>):</p> |
| 89 | +<pre class="code">Secondary result "io.sf.carte.doc.style.css.mark.XMLBuildBenchmark.markBuildDOM4J: stack": |
| 90 | +Stack profiler: |
| 91 | + |
| 92 | +....[Thread state distributions].................................................................... |
| 93 | + 72,3% BLOCKED |
| 94 | + 27,6% RUNNABLE |
| 95 | + |
| 96 | +....[Thread state: BLOCKED]......................................................................... |
| 97 | + 72,3% 100,0% java.util.Collections$SynchronizedMap.get |
| 98 | + org.dom4j.tree.QNameCache.get |
| 99 | + org.dom4j.DocumentFactory.createQName |
| 100 | + org.dom4j.tree.NamespaceStack.createQName |
| 101 | + org.dom4j.tree.NamespaceStack.pushQName |
| 102 | +</pre> |
| 103 | +<p>So its usage is not recommended for multi-core systems.</p> |
| 104 | +<p>DOM implementations that are CSS-enabled (like Css4j-DOM4j and Css4j's native DOM) are necessarily a bit slower than plain DOM, and Css4j's native DOM is the slowest of the |
| 105 | +measured implementations (especially when processing large XML files). More benchmarks are needed to verify that the balance of optimizations/implementation decisions in the native DOM is adequate, and try to improve its performance.</p> |
| 106 | +</div> |
| 107 | +</div> |
| 108 | +<div class="footnote"> |
| 109 | +</div> |
| 110 | +</div> |
| 111 | +</div> |
| 112 | +</body> |
| 113 | +</html> |
0 commit comments