Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ node_modules
# Generated files
/coverage/
/dist/
/tests/bench/results/
/tests/integration/*/dist/
/spec/tmp/*
5 changes: 2 additions & 3 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@
}
},
{
"files": ["tests/bench/**/*.js"],
"files": ["tests/bench/**/*.mjs"],
"rules": {
"no-console": "off",
"no-var": "off"
"no-console": "off"
}
},
{
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,36 @@ does have some big performance advantages. Justin Marney, a.k.a.
rewritten Handlebars (current version) is faster than the old version,
with many performance tests being 5 to 7 times faster than the Mustache equivalent.

### Benchmarks

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.

```bash
# Run benchmarks (auto-labels with current git branch)
npm run bench

# Run with a custom label
npm run bench -- --label my-optimization

# Compare results
npm run bench:compare

# Or specify files explicitly
npm run bench:compare -- bench/results/bench-*-main.md bench/results/bench-*-feat.md
```

Results are saved as timestamped Markdown files in `bench/results/`. Each report includes ops/sec, avg latency, p50/p75/p99 percentiles, and sample counts.

Typical workflow for comparing branches:

```bash
git checkout main && npm run bench
git checkout my-feature && npm run bench
npm run bench:compare
```

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%).

## Upgrading

See [release-notes.md](https://github.com/handlebars-lang/handlebars.js/blob/master/release-notes.md) for upgrade notes.
Expand Down
3 changes: 3 additions & 0 deletions lib/handlebars/compiler/javascript-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ JavaScriptCompiler.prototype = {
}
}

// Release AST/compiler references only needed during compilation for dedup
this.context.environments.length = 0;

if (this.environment.usePartial) {
ret.usePartial = true;
}
Expand Down
Loading