Skip to content

bench: add RenderToString suite covering the string-returning API - #650

Merged
rexm merged 1 commit into
masterfrom
bench/render-to-string
Aug 5, 2026
Merged

bench: add RenderToString suite covering the string-returning API#650
rexm merged 1 commit into
masterfrom
bench/render-to-string

Conversation

@rexm

@rexm rexm commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary

Adds a RenderToString benchmark suite covering the string-returning template API — the most common way the library is consumed in practice.

Why

All existing Render* suites invoke templates against TextWriter.Null. That measures path-resolution and iteration overhead well, but a no-op writer hides the entire output side of rendering: HTML encoding and the actual StringBuilder-backed writes. During benchmarking of output-path optimizations, TextWriter.Null produced misleading results in both directions — it understated real-world wins (per-char writes are nearly free on a null writer) and manufactured regressions that don't exist for real writers (TextWriter's base span implementation rents/copies via ArrayPool, which StringWriter/StreamWriter never hit).

What it measures

  • A 50-item {{#each}} list template rendered through HandlebarsTemplate<object, object> (i.e. template(data) returning a string), which exercises the pooled ReusableStringWriter path.
  • Two content cases:
    • clean — values contain nothing that needs HTML escaping (typical data);
    • html — values are dense with characters that must be escaped (worst case for encoder fast paths).

Runtime cost: ~1 minute per full suite run (2 cases × ~30s), well within the benchmark time budget.

Baseline numbers (master, Apple M4, .NET 10)

Method Content Mean Error StdDev Gen0 Gen1 Allocated
Render clean 13.95 us 0.108 us 0.095 us 3.9215 0.2289 32.09 KB
Render html 14.75 us 0.118 us 0.110 us 4.3030 0.2594 35.31 KB

🤖 Generated with Claude Code

The existing Render* suites write to TextWriter.Null, which measures path
resolution but hides the real output costs (HTML encoding, StringBuilder-
backed writes). This suite renders through the string-returning template
API with clean values and escape-dense values as separate cases.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@rexm
rexm enabled auto-merge August 5, 2026 03:46
@rexm
rexm merged commit ca0913a into master Aug 5, 2026
7 checks passed
@rexm
rexm deleted the bench/render-to-string branch August 5, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant