Skip to content

Fix wasm allocation, add regression tests for benchmark times for all artifacts - #60

Merged
sc2ben merged 4 commits into
mainfrom
59-wasm-rendering-markdown-with-diagrams-is-52ms
Jun 6, 2026
Merged

sc2ben merged 4 commits into
mainfrom
59-wasm-rendering-markdown-with-diagrams-is-52ms

Conversation

@tsunaminoai

Copy link
Copy Markdown
Contributor

This pull request introduces significant improvements to benchmarking, WASM build configuration, and the renderer implementation for the project. The changes add a mermaid-heavy benchmark input, expand the benchmarking suite to cover mermaid diagrams, optimize and expose multiple WASM render entrypoints with different allocators and caching strategies, and improve CI and Nix flake integration for WASM builds and regression checks.

Benchmarking and Input Improvements:

  • Added a new committed benchmark input bench/input-mermaid.md containing multiple mermaid diagram blocks and representative GFM content to better evaluate parser and renderer performance on diagram-heavy documents.
  • Updated the benchmarking suite in flake.nix to run a separate set of benchmarks using the new mermaid-heavy input, and to generate a dedicated results table for these runs. [1] [2] [3] [4]

WASM Build and CI Enhancements:

  • Added a standalone WASM build job to .github/workflows/ci.yml so that WASM builds appear as a distinct required check in GitHub branch rules and are independently verifiable. Also added a benchmark regression job that compares the current build against the last release using hyperfine.
  • Updated flake.nix to add a WASM build check (checks.wasm) to the flake outputs, ensuring WASM module production is verified in CI.

Renderer and Allocator Optimizations (WASM):

  • Refactored examples/wasm/zigmark-wasm.zig to provide multiple render entrypoints:
    • render_html_arena (persistent arena allocator for fast repeated renders)
    • render_html_fba (fixed buffer allocator for zero-syscall rendering)
    • render_html_nomermaid (renders without mermaid for overhead measurement)
    • flush_mermaid_cache (clears the SVG cache)
    • parse_only (isolates parse time for benchmarks)
    • Added an efficient mermaid SVG cache to avoid redundant diagram rendering. [1] [2]
  • Updated all buffer allocation and deallocation routines to use the appropriate allocator, and ensured correct memory management for each render mode. [1] [2]

Build Configuration:

  • Changed the default WASM optimization mode from ReleaseSmall to ReleaseFast for improved performance in benchmarks.
  • Exposed new WASM entrypoints in the Zig build for all new render and utility functions.

These changes collectively enable more accurate, representative benchmarking (especially for mermaid-heavy documents), improve the reliability and reproducibility of WASM builds in CI, and provide optimized rendering pathways for different usage scenarios.

- Introduced caching for Mermaid SVG outputs to optimize rendering performance.
- Added support for multiple allocators: page allocator, arena allocator, and fixed buffer allocator.
- Updated rendering functions to utilize the new caching mechanism and allocators.
- Implemented a function to flush the Mermaid cache.
- Modified the `alloc_buf` and `free_buf` functions to use the page allocator.
- Enhanced the CI configuration to include WASM build checks.
- Created a script to set up GitHub branch protection rules requiring CI checks.
@tsunaminoai tsunaminoai self-assigned this Jun 6, 2026
Copilot AI review requested due to automatic review settings June 6, 2026 01:19
@tsunaminoai tsunaminoai added the bug Something isn't working label Jun 6, 2026
@tsunaminoai tsunaminoai linked an issue Jun 6, 2026 that may be closed by this pull request
@tsunaminoai
tsunaminoai enabled auto-merge (squash) June 6, 2026 01:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the project’s performance benchmarking and WASM demo/runtime by adding a mermaid-heavy benchmark fixture, expanding CI with standalone WASM + benchmark regression checks, and refactoring the WASM renderer to expose multiple entrypoints/allocators with a mermaid SVG cache.

Changes:

  • Added a committed mermaid-heavy benchmark input and extended the nix run .#bench flow to publish a dedicated results table for it.
  • Added CI jobs for a standalone WASM build check and a release-vs-current benchmark regression gate.
  • Refactored the WASM demo/entrypoints to support multiple allocator modes and richer in-browser benchmarking/diagnostics UI.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
scripts/setup-branch-rules.sh Adds a script to configure branch rulesets requiring CI checks (with some mismatches between comments/intended scope vs current ruleset JSON).
flake.nix Adds a WASM flake check and extends the benchmark app to run and publish mermaid-heavy results.
examples/wasm/zigmark-wasm.zig Introduces multiple WASM render entrypoints (arena/FBA/no-mermaid/parse-only) plus a small mermaid SVG cache.
examples/wasm/index.html Adds a benchmark overlay, presets, and JS-side mermaid timing comparison (with an async update race that should be guarded).
build.zig Changes default WASM optimize mode to ReleaseFast and exports new WASM symbols (help text needs updating).
bench/input-mermaid.md Adds a benchmark fixture containing multiple mermaid blocks plus representative GFM content.
.github/workflows/ci.yml Adds standalone wasm and bench-regression jobs to make those checks independently required.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/setup-branch-rules.sh Outdated
Comment on lines +4 to +6
# Creates (or updates) a ruleset named "main-branch-protection" that requires
# all four CI checks to pass before merging into main or zig-* branches.
#
Comment thread scripts/setup-branch-rules.sh Outdated
Comment on lines +41 to +45
conditions: {
ref_name: {
include: ["~ALL"],
exclude: []
}
Comment thread build.zig Outdated
@@ -293,7 +293,7 @@ pub fn build(b: *std.Build) void {
std.builtin.OptimizeMode,
"wasm-optimize",
"Optimization for WASM target (default: ReleaseSmall)",
Comment thread examples/wasm/index.html
const rendererSelect = document.getElementById('renderer-select');
const copyOutputBtn = document.getElementById('copy-output');

let debounce = null;
Comment thread examples/wasm/index.html
Comment on lines +331 to 333
async function update() {
const md = editor.value;
const renderer = rendererSelect.value;
Comment thread examples/wasm/index.html
@sc2ben
sc2ben self-requested a review June 6, 2026 03:43

@sc2ben sc2ben left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding rulesets to repo for IaC

@sc2ben
sc2ben disabled auto-merge June 6, 2026 04:17
@sc2ben
sc2ben merged commit d96264f into main Jun 6, 2026
4 checks passed
@sc2ben
sc2ben deleted the 59-wasm-rendering-markdown-with-diagrams-is-52ms branch June 6, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WASM rendering markdown with diagrams is ~5.2ms

3 participants