NAME

problem48-template-service-benchmark - compare Template Toolkit service and compiled scalar-template reuse

PURPOSE

This benchmark compares many request-like scopes, each with one Template Toolkit service and five scalar bodies. The baseline reparses and compiles source on each render; the candidate uses PageRuntime's request-scoped service and bounded worker-local compiled scalar-template cache. --workload repeated uses five identical sources per request, while --workload distinct uses five different sources. Both arms render dynamic stash values and an INCLUDE file.

WHY IT EXISTS

The Problem 48 NYTProf route profile showed repeated Template Toolkit parsing and compilation in PageRuntime. This benchmark checks exact output parity while isolating scalar-template reuse from route dispatch. The distinct workload approximates requests whose page and navigation fragments have different source bodies; neither workload is a whole-route latency claim.

WHEN TO USE

Run this after changing PageRuntime::_template_processor_for_roots or PageRuntime::_template_document_for_source. It uses a private temporary include root and does not touch dashboard user state.

HOW TO USE

perl script/problem48-template-service-benchmark
perl script/problem48-template-service-benchmark --iterations 500 --runs 21 --workload repeated
perl script/problem48-template-service-benchmark --iterations 500 --runs 21 --workload distinct

OUTPUT

The command prints request count, renders per request, workload, exact parity, median milliseconds per render for each path, and their ratio. This isolated measurement must not be presented as end-to-end dashboard latency or as a 50x result for all routines.

SAFETY

No shell commands are executed. The temporary directory is automatically removed at process exit. Errors from service creation or template processing are fatal and remain visible.