Skip to content

Benchmark framework hot paths and accelerate HTML rendering - #34

Merged
zth merged 7 commits into
mainfrom
perf/framework-benchmarks
Sep 22, 2026
Merged

zth merged 7 commits into
mainfrom
perf/framework-benchmarks

Conversation

@zth

@zth zth commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Reduce allocation and promise overhead in buffered HTML rendering while preserving escaping, deferred component execution and request-context isolation.

Changes

  • Accumulate HTML strings directly, fast-path primitive children, update provider context at component invocation, and allocate pending work only for async subtrees.
  • Add a dedicated compiler JSX factory; retain legacy h(). Avoid extra promise coordination for synchronous trees and single async subtrees.
  • Allocate controller collections lazily, use dictionaries for internal route lookup, construct fresh default Headers from a record, and skip an absent after-render hook.
  • Cover numeric-zero children, error boundaries, async ordering, contexts, headers and controller isolation with regression tests. Keep reusable benchmark fixtures, runner and CI smoke coverage. Use OS-assigned ports for in-process integration tests.
  • Remove experimental reports, recorded samples, research notes, one-off comparison tooling and historical-results tests from the final diff.

Final direct measurements against main

Baseline 9dd19d2693e82d2f979c8d54fe682237d78b72ae; candidate implementation 5bbd562a235c59a75c726030c74835d8c74bc681 (framework source hashes matched the delivered implementation). Bun 1.3.14, Linux x64, AMD RYZEN AI MAX+ 395, shared development host. Each workload/version ran in a fresh process: one second warmup, nine approximately 60 ms samples, three alternating baseline/candidate pairs. Values are medians of process medians. These are direct comparisons, not multiplied optimization-round ratios.

Workload Main µs/op Final PR µs/op Speedup
html/text-safe-4k 0.224 0.196 1.15×
html/text-escaped 1.900 1.855 1.02×
html/attributes 0.549 0.546 1.01×
html/styles 0.358 0.119 3.01×
html/list-100 52.883 25.828 2.05×
html/list-100-utf8 51.578 44.355 1.16×
html/create-and-render-100 69.073 41.940 1.65×
html/components-100 15.205 7.775 1.96×
html/context-depth-20 2.078 1.894 1.10×
html/raw-4k 0.020 0.001 14.21×
html/small-sync-async-api 0.287 0.098 2.92×
html/single-promise 0.520 0.277 1.88×
html/async-api-sync-tree 54.583 26.852 2.03×
html/async-sparse 140.428 43.865 3.20×
html/async-dense-100 41.748 26.078 1.60×
html/async-nested 56.136 25.653 2.19×
context/als-run 0.009 0.010 0.88×
context/als-read-100 0.230 0.251 0.92×
context/als-await 0.121 0.126 0.96×
request/controller 0.099 0.086 1.14×
request/minimal 5.062 4.770 1.06×
request/page-100 82.424 58.079 1.42×
request/context-components-100 11.188 10.192 1.10×
request/head-title-body 8.179 6.834 1.20×
request/route-hit-1000 4.084 3.539 1.15×
request/route-miss-1000 3.561 3.240 1.10×

The complete page request takes 29.5% less time (1.42× speedup). Requests include Request creation, framework processing and Response.text(), without sockets, TLS or a database. These figures do not predict equivalent production HTTP throughput gains.

Escaping-heavy text and attributes are essentially unchanged. Minimal requests improve only 6%, with overlapping process ranges. AsyncLocalStorage is unchanged and its controls measured slightly slower; no ALS improvement is claimed. Raw HTML's 14.21× ratio saves only about 19 ns and is susceptible to JIT elimination, so it is not a useful application speedup claim. UTF-8 materialization narrows rendering gains to 1.16×. Streaming performance was excluded.

Dedicated JSX entry points and synchronous fast paths were informed by KitaJS, Hono and Preact source implementations. No weaker escaping or eager component execution was adopted. A generic variadic-factory rewrite was discarded after regressions.

Validation

  • Cleaned-up commit 0908cb9: 120 tests passed, 0 failures, 310 assertions locally. ReScript build and all benchmark smoke cases passed. GitHub CI is green on the same commit.

The retained benchmark fixtures verify expected output before and after measurement; tests exercise them twice. Renderer and request regressions cover promise ordering/rejection, provider scope, concurrent requests, legacy JSX, immutable compiler props, numeric zero, headers, lazy collections and route behavior. CI builds ReScript, runs the full tests and runs benchmark smoke. Measurement history is retained only in this PR discussion, not the merge diff.

@zth
zth marked this pull request as ready for review September 22, 2026 07:02
@zth

zth commented Sep 22, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T07:07:20.231693Z 0908cb9 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 0908cb908b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@zth
zth merged commit 16fc7b0 into main Sep 22, 2026
1 check passed
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