Performance Tuning Guide
This guide focuses on concrete runtime knobs and operational practices to reduce latency and prevent regressions.
1. Establish a Baseline
Run the benchmark suite first:
pnpm benchFor CI artifact output:
pnpm bench:ci
# writes .artifacts/benchmarks/runtime-bench.jsonUseful environment variables for benchmark sensitivity:
RENDERIFY_BENCH_TIME_MS=400
RENDERIFY_BENCH_WARMUP_MS=2002. Measure the Real Pipeline
If you use @renderify/core, provide your own DefaultPerformanceOptimizer and read metrics from it:
import {
createRenderifyApp,
DefaultPerformanceOptimizer,
} from "@renderify/core";
const perf = new DefaultPerformanceOptimizer();
const app = createRenderifyApp({
// ...other dependencies
performance: perf,
});
app.on("rendered", (payload) => {
console.log("render duration(ms):", payload?.metric?.durationMs);
});
console.table(perf.getMetrics());If you use renderer-only integration, inspect these outputs on every render:
security.issuesexecution.diagnostics- preflight result (
runtime.probePlan(plan))
3. Tune the Highest-Impact Knobs
| Knob | Default | Impact | Tradeoff |
|---|---|---|---|
enableDependencyPreflight | true | Better safety and earlier failure signals | Adds startup latency |
failOnDependencyPreflightError | false | Fast fail for strict CI/prod lanes | Lower tolerance for flaky CDNs |
remoteFetchTimeoutMs | 12000 | Prevents long hangs | Too low can create false timeouts |
remoteFetchRetries | 2 | Better resilience | More retries increase tail latency |
remoteModuleMaxBytes | 8388608 | Bounds memory per remote module | Too low rejects large bundles |
remoteFallbackCdnBases | ['https://esm.sh'] | Better availability | Must align with security host policy |
browserSourceSandboxMode | browser:worker, server:none | Containment for reviewed source | Worker/iframe adds overhead |
browserSourceSandboxTimeoutMs | 4000 | Bounds worst-case source execution | Too low may cut valid workloads |
runtimeSourceJsxHelperMode | auto | Predictable transpilation behavior | always can add minor output overhead |
autoPinLatestModuleManifest | true | Great DX for bare imports | Latest-based resolution can drift |
4. Scenario Presets
Low-Latency Interactive Preview
Use in chat preview paths where responsiveness matters more than strict fail-fast.
const runtime = new DefaultRuntimeManager({
enableDependencyPreflight: false,
remoteFetchTimeoutMs: 6000,
remoteFetchRetries: 1,
browserSourceSandboxMode: "worker",
browserSourceSandboxTimeoutMs: 2500,
});Deterministic Production Rendering
Use when reproducibility and policy guarantees are required.
const runtime = new DefaultRuntimeManager({
enforceModuleManifest: true,
enableDependencyPreflight: true,
failOnDependencyPreflightError: true,
allowIsolationFallback: false,
browserSourceSandboxMode: "worker",
browserSourceSandboxFailClosed: true,
remoteFallbackCdnBases: [],
});High-Volume Concurrency
- Reuse initialized runtime instances instead of creating a new runtime per request.
- Keep
serializeTargetRendersenabled for same-target UI safety. - Bound render cancellations with
AbortControllerto shed load quickly.
5. Browser Cold Start
Where the time goes on a first render of model-written JSX in a browser, from a desktop on a typical connection to the JSPM and esm.sh CDNs:
| Phase | Typical cost |
|---|---|
| Babel transform of a 120-line component | 5-10 ms |
| Frame runner boot (download excluded) | ~190 ms full runner, ~12 ms plan-only runner |
| Module graph download | seconds; one CDN round trip per dependency level |
Network round trips dominate, so the runtime focuses on not repeating them:
- Shared module responses (browsers). Responses for version-pinned CDN URLs
are cached for the life of the document; responses for ranges and tags
(
@^11.5.0) are reused for 10 minutes. Dependency preflight, materialization, and later renders share one fetch per URL, and concurrent requests share one in-flight fetch. Each runtime instance still applies its own network policy, integrity, pinning, and size checks to cached responses. CallclearRemoteModuleCache()to drop them. - Shared auto-pin lookups (browsers).
package.jsonfor an exact version is fetched once per document; "latest version" answers are reused for 10 minutes. - No wasted pinning.
seedPlaygroundBrowserModules(plan)registers the Preact or React builds the browser source path will use, so auto-pinning skips them. - Plan-only runner.
@renderify/framewithrunner: "plan"loads a 59 KiB (gzip) runner without Babel instead of 623 KiB. - Placeholder. The frame shows a loading state while a source render downloads its module graph.
Measured with the website Playground samples in @renderify/frame:
| Sample | Before | After |
|---|---|---|
| Preact card, first render | 5.0-6.6 s | ~2.6 s |
| Preact card, re-render in the same frame | ~1.3 s | ~10 ms |
| React + Material UI todo, first render | ~7.5 s | ~5.3 s |
| React + Material UI todo, re-render in the same frame | ~3.3 s | ~60 ms |
First renders of npm-heavy components remain bound by CDN latency: one round trip per dependency level, plus a security audit fetch for each Preact module the browser imports natively. Self-hosting modules near your users, or rendering declarative RuntimePlans, avoids that cost entirely.
6. Memory and Lifecycle Hygiene
The runtime keeps in-memory module URL caches for browser source execution. For long-lived pages:
- Reuse a runtime instance for steady traffic.
- Periodically recycle runtime instances in very long sessions.
- Always call
runtime.terminate()on shutdown/unmount to clear caches and revoke blob URLs.
Example:
await runtime.initialize();
try {
await runtime.execute({ plan });
} finally {
await runtime.terminate();
}7. Protect Against Regressions
Use these checks in CI:
pnpm typecheckpnpm unitpnpm compatpnpm bench:ciand compare key metrics (meanMs,rme,samples)
Suggested policy:
- Block merge if
meanMsregresses more than an agreed threshold (for example 10%). - Track trend over multiple runs instead of a single datapoint to reduce noise.
8. Quick Debug Checklist for Slow Renders
- Run
probe-planto isolate dependency failures from execution logic. - Inspect
execution.diagnosticsfor timeout and import budget messages. - Check module count and transitive dependency size in
plan.sourceimports. - Reduce fallback retries if tail latency dominates.
- Switch sandbox mode only after confirming it is the dominant overhead.
