unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

bench/xlang/site/index.html
1<!doctype html>2<html lang="en">3<head>4<meta charset="utf-8">5<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">6<title>MoonBit Unicode performance</title>7<meta name="description" content="How fast the MoonBit Unicode library is on every merge to main, and against ICU4X, ICU4C and JavaScript's built-ins.">8<link rel="preconnect" href="https://fonts.googleapis.com">9<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Schibsted+Grotesk:wght@500;700;800&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap">10<link rel="stylesheet" href="style.css">11</head>12<body>13<div class="wrap">14  <header>15    <div class="eyebrow">moonbit-community/unicode · performance</div>16    <h1>MoonBit Unicode performance</h1>17    <p class="lead prose">How fast the MoonBit Unicode library normalizes, segments, resolves bidi, converts domain names and maps case: on every merge to main, and against ICU4X, ICU4C and, on the JS backend, JavaScript's own built-ins. Lower times are better.</p>18  </header>1920  <section id="history">21    <div class="prose" style="display:flex;flex-direction:column;gap:8px">22      <div class="eyebrow">Every merge to main</div>23      <h2>Changes on main</h2>24      <p class="muted">For every merge, CI builds the MoonBit harness at the merge and at its first parent, runs the two in turns on the same GitHub runner and keeps the fastest round of each case. Each cell is the change in time, the geometric mean over the operation's inputs: green is faster, red is slower. Runners are shared machines, so changes within the run's noise, shown in grey, mean nothing.</p>25      <p class="muted">Tick a merge, then another, to combine the run of merges from one to the other: the combined row is the change from before the oldest to after the newest, chained input by input from each merge's own comparison. Their noise adds up, so a combined change has to be larger than a single one to leave the grey. The address keeps the range, to link to.</p>26    </div>27    <div class="controls">28      <div class="ctl"><span class="eyebrow">Backend</span><div class="chips" id="backend-chips" role="group" aria-label="Backend"></div></div>29      <div class="ctl"><span class="eyebrow">Combine</span><div class="chips" id="combine-chips" role="group" aria-label="Combine merges"></div></div>30    </div>31    <div id="history-body"></div>32  </section>3334  <section id="snapshot">35    <div class="prose" style="display:flex;flex-direction:column;gap:12px">36      <div class="eyebrow">Cross-language snapshot</div>37      <h2>Against other libraries</h2>38      <p class="muted">A full run of every harness on one quiet machine, published by hand. Times are nanoseconds per code point, per call for IDNA and Punycode.</p>39      <div class="meta" id="snapshot-meta"></div>40    </div>41    <div class="findings" id="findings"></div>42  </section>4344  <section id="icu4x">45    <div class="prose" style="display:flex;flex-direction:column;gap:8px">46      <div class="eyebrow">Native and Wasm</div>47      <h2>Against ICU4X and ICU4C</h2>48      <p class="muted">Geometric mean over each operation's inputs. MoonBit, ICU4C and ICU4X's UTF-16 API all work on UTF-16, and only libraries that take UTF-16 are shown, so every bar reads the same bytes. ICU4C is used through <code>UnicodeString</code>, ICU4X through its <code>_utf16</code> APIs. The verdict under each chart compares MoonBit native with the fastest of the others. MoonBit runs on two WebAssembly backends: wasm-gc, whose objects V8's garbage collector manages, and wasm, which keeps everything in linear memory with reference counting.</p>49    </div>50    <div class="legend" id="legend-icu"></div>51    <div class="grid" id="grid-icu"></div>52  </section>5354  <section id="js">55    <div class="prose" style="display:flex;flex-direction:column;gap:10px">56      <div class="eyebrow">JavaScript backend</div>57      <h2>MoonBit compiled to JS vs the built-ins</h2>58      <p class="answer">JavaScript does have built-ins for some of this. <code>String.prototype.normalize</code> and <code>Intl.Segmenter</code> are implemented in C++ inside V8, on top of ICU4C. Node also ships <code>url.domainToASCII</code> (the ada URL parser) and the deprecated <code>punycode</code> module, which is plain JS. There is no built-in for bidi resolution or an NFC check, so those have no JS counterpart here.</p>59      <p class="muted">So this pits MoonBit compiled to JavaScript against native ICU code reached through V8. Every Node case pays the cost of crossing from JavaScript into the runtime, and <code>domainToASCII</code> converts the string to UTF-8 inside it. <code>domainToUnicode</code> first runs the whole ToASCII conversion and then decodes the result back, so it always costs more than ToASCII.</p>60    </div>61    <div class="legend" id="legend-js"></div>62    <div class="grid" id="grid-js"></div>63  </section>6465  <section id="cases">66    <div class="prose" style="display:flex;flex-direction:column;gap:8px">67      <div class="eyebrow" id="case-count">Every case</div>68      <h2>Every input, every implementation</h2>69      <p class="muted">Each cell is the fastest round of the snapshot. The second line is the time relative to the baseline you pick: green is faster, red is slower.</p>70    </div>71    <div class="controls">72      <div class="ctl"><span class="eyebrow">Operation</span><div class="chips" id="op-chips" role="group" aria-label="Operation"></div></div>73      <div class="ctl"><label class="eyebrow" for="baseline">Relative to</label><select id="baseline"></select></div>74    </div>75    <div class="table-scroll"><table id="case-table"></table></div>76  </section>7778  <section id="method">79    <div class="eyebrow">Method and caveats</div>80    <div class="notes">81      <p><b>Protocol.</b> Every harness reads the same input files, doubles the iteration count until one sample takes at least 5 ms, and keeps the fastest of 5 samples, counting that one. Each cell is the fastest of several rounds, which run one harness at a time. File I/O and input preparation are outside the timed calls. Every result is kept where it can be read later, so that no optimizer can drop the work that builds it.</p>82      <p><b>Changes on main.</b> Both commits run the harness of the merge, so a change to the harness does not show up as a change to the library. They take turns going first in each round. The noise of a run is the median over its cases of slowest round / fastest round; a change no larger than that is greyed out.</p>83      <p><b>Combined merges.</b> Each merge is compared on its own runner, and the runners differ in speed, so times are never compared across merges, only each merge's ratio of head to base. Per input, the ratios of the merges multiply into the change over the range, and the geometric mean over the inputs that every merge measured gives the operation's. Inputs added within the range are left out. The noise is the merges' noises added in log space as a root sum of squares. For a figure measured in one go, run <code>bench/xlang -- --base &lt;older commit&gt;</code>.</p>84      <p><b>Inputs.</b> Normalization uses the 14 ICU normperf corpora, as they are and converted to NFD. <code>NFD → NFC</code> composes the decomposed copy, forcing real work. Most corpora are already NFC, so MoonBit, ICU4X and Node can return the input unchanged on NFC, NFKC and the NFC check.</p>85      <p><b>Encodings.</b> Every implementation shown in the snapshot takes UTF-16: MoonBit's <code>String</code>, ICU4C's <code>UnicodeString</code>, ICU4X's <code>_utf16</code> APIs, <code>unicode-bidi</code>'s UTF-16 module and JavaScript strings. The harness also measures Rust libraries that read UTF-8. They are left out here: UTF-8 makes ASCII cheaper and CJK dearer, so those numbers mix the encoding with the algorithm.</p>86      <p><b>Builds.</b> MoonBit native is compiled through C with clang. Wasm-gc and wasm run in V8 under <code>moonrun</code>. The JS backend runs under Node. The Rust harness is a release build (fat LTO, one codegen unit) with ICU4X's compiled data.</p>87      <p><b>Case and categories.</b> The harness feeds ICU4X and Rust's <code>std</code> these per-character lookups from UTF-8 strings, so the snapshot compares them with ICU4C only. Full uppercase mapping has no UTF-16 peer and is not shown there.</p>88      <p><b>Wasm and wasm-gc.</b> The wasm backend shares the native backend's SIMD path, so it beats wasm-gc on NFC, NFKC and the NFC check, where the clean-text scan dominates. Elsewhere it is usually slower: it reference-counts and allocates with MoonBit's own allocator inside linear memory, while wasm-gc allocates from V8's collector. Results also depend on what ran earlier in the same process, as V8's heap grows, so both the snapshot and the changes on main come from runs of the full suite.</p>89    </div>90  </section>9192  <footer>Source: <code>bench/xlang</code>. Run <code>moon run --target native bench/xlang</code> for the snapshot, <code>moon run --target native bench/xlang -- --base HEAD^</code> for the changes of one commit. See <code>bench/xlang/README.md</code>.</footer>93</div>94<script src="dashboard.js"></script>95</body>96</html>97