[llvm-branch-commits] [llvm] [llvm][mustache] Avoid excessive hash lookups in EscapeStringStream (PR #160166)

Paul Kirth via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Sep 22 18:13:25 PDT 2025


ilovepi wrote:

**This patch:**
   | Benchmark | Baseline (ns) | Experiment (ns) | Speedup |
   | :--- | :--- | :--- | :--- |
   | `LargeOutputString` | 8,926,576 | 591,254 | ~93% |
   | `StringRendering/Escaped` | 18,196,698 | 10,280,591 | ~44% |
   | `DeeplyNestedRendering` | 2,799 | 2,474 | ~12% |
   | `PartialsRendering` | 211,153,502 | 197,101,139 | ~7% |
   | `DeepTraversal` | 4,412,011 | 4,148,482 | ~6% |
   | `HugeArrayIteration` | 61,887,053 | 58,737,900 | ~5% |

**std::array<string,256>:**

   | Benchmark | Baseline (ns) | Experiment (ns) | Change |
   | :--- | :--- | :--- | :--- |
   | `StringRendering/Escaped` | 18,196,698 | 16,979,453 | ~7% faster |
   | `PartialsRendering` | 211,153,502 | 198,234,189 | ~6% faster |
   | `LargeOutputString` | 8,926,576 | 8,423,018 | ~6% faster |
   | `HugeArrayIteration` | 61,887,053 | 63,989,131 | ~3% slower |

I didn't try combining them. Its not clear how we'd initialize the list of special escape characters in the stream, unless we assume you can't override them. Besides, we do many fewer lookups now, so IDK how worth it it is in practice. The Mustache generation is about 20% faster w/ this patch. That part is only a small fraction of the overall execution time, but it did a make a difference.

https://github.com/llvm/llvm-project/pull/160166


More information about the llvm-branch-commits mailing list