Skip to content

Commit bf93baf

Browse files
authored
Modernize benchmarks (#2132)
* Introduce benchmarks
1 parent 70b8f11 commit bf93baf

37 files changed

Lines changed: 1223 additions & 4399 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ node_modules
1414
# Generated files
1515
/coverage/
1616
/dist/
17+
/tests/bench/results/
1718
/tests/integration/*/dist/
1819
/spec/tmp/*

.oxlintrc.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@
116116
}
117117
},
118118
{
119-
"files": ["tests/bench/**/*.js"],
119+
"files": ["tests/bench/**/*.mjs"],
120120
"rules": {
121-
"no-console": "off",
122-
"no-var": "off"
121+
"no-console": "off"
123122
}
124123
},
125124
{

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,36 @@ does have some big performance advantages. Justin Marney, a.k.a.
104104
rewritten Handlebars (current version) is faster than the old version,
105105
with many performance tests being 5 to 7 times faster than the Mustache equivalent.
106106

107+
### Benchmarks
108+
109+
The project includes a comprehensive benchmark suite (powered by [tinybench](https://github.com/tinylibs/tinybench)) that measures compilation, execution, precompilation, and end-to-end performance across templates of varying size and complexity.
110+
111+
```bash
112+
# Run benchmarks (auto-labels with current git branch)
113+
npm run bench
114+
115+
# Run with a custom label
116+
npm run bench -- --label my-optimization
117+
118+
# Compare results
119+
npm run bench:compare
120+
121+
# Or specify files explicitly
122+
npm run bench:compare -- bench/results/bench-*-main.md bench/results/bench-*-feat.md
123+
```
124+
125+
Results are saved as timestamped Markdown files in `bench/results/`. Each report includes ops/sec, avg latency, p50/p75/p99 percentiles, and sample counts.
126+
127+
Typical workflow for comparing branches:
128+
129+
```bash
130+
git checkout main && npm run bench
131+
git checkout my-feature && npm run bench
132+
npm run bench:compare
133+
```
134+
135+
When run without arguments, `bench:compare` auto-selects two result files: if a file labelled "main" exists it is always used as the baseline, otherwise the older file is the baseline. The comparison uses p75 latency for the diff to filter outliers, and marks changes with `!` (>2%) and `!!` (>5%).
136+
107137
## Upgrading
108138

109139
See [release-notes.md](https://github.com/handlebars-lang/handlebars.js/blob/master/release-notes.md) for upgrade notes.

lib/handlebars/compiler/javascript-compiler.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ JavaScriptCompiler.prototype = {
173173
}
174174
}
175175

176+
// Release AST/compiler references only needed during compilation for dedup
177+
this.context.environments.length = 0;
178+
176179
if (this.environment.usePartial) {
177180
ret.usePartial = true;
178181
}

0 commit comments

Comments
 (0)