Skip to content

Async Mermaid/Liquid rendering with sync-vs-async benchmarks - #6

Merged
0xtlt merged 4 commits into
mainfrom
t/async-mermaid-highlight-bench-50c5
Jul 29, 2026
Merged

Async Mermaid/Liquid rendering with sync-vs-async benchmarks#6
0xtlt merged 4 commits into
mainfrom
t/async-mermaid-highlight-bench-50c5

Conversation

@0xtlt

@0xtlt 0xtlt commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Render Mermaid fences asynchronously with Tokio spawn_blocking on a shared, CPU-capped runtime (max_blocking_threads = 2–8).
  • Keep Liquid highlighting synchronous so one TextMate highlighter is reused.
  • Merge Mermaid results through structured body segments (no string placeholders), so user content cannot collide with job markers.
  • Add regression tests for literal marker text and mixed Mermaid/Liquid ordering.
  • Include heavy Mermaid/Liquid benchmark fixture and harness; machine-specific benches/results/*.json is gitignored.

Review fixes

  1. Placeholder injection → structured BodySegment::{Text,Job}
  2. Unbounded spawn_blocking → capped blocking pool on a process-wide runtime
  3. Per-fence Liquid highlighter init → sync path with reused highlighter
  4. Missing tests → marker collision + mixed order/asset stability
  5. Drop tracked bench JSON snapshots; ignore benches/results/

Benchmark (4× Xeon @ 2400 MHz, 2 warmups + 7 runs)

Fixture: benches/fixtures/heavy-async.md (48 Mermaid + 24 Liquid + 8 Rust). Summary lives in benches/README.md.

Metric Sync Async Delta
Wall time avg 0.874 s 0.309 s -64.7%
CPU utilization avg 101% 296% +193%
Max RSS peak 65,752 KB 71,300 KB +8.4%
Estimated CPU cycles avg 2.112e9 2.211e9 +4.7%

Hardware PMU cycles unavailable (perf_event_open EACCES); cycles estimated as (user+sys) * 2400MHz.

Open in Web Open in Cursor 

cursoragent and others added 4 commits July 29, 2026 13:36
Collect independent Mermaid and Liquid fences during Markdown parsing and
render them with Tokio spawn_blocking so CPU-bound work can overlap across
cores. Add a heavy fixture and sync-vs-async benchmark results.

Co-authored-by: Thomas <0xtlt@users.noreply.github.com>
Replace string placeholders with structured body segments so user content
cannot collide with job markers, cap the Tokio blocking pool to available
CPUs, reuse one Liquid highlighter on the sync path, and add regression
tests for marker text and mixed Mermaid/Liquid ordering.

Co-authored-by: Thomas <0xtlt@users.noreply.github.com>
Stop tracking benches/results snapshots so local timing runs stay out of
git; keep the fixture, harness, and README summary.

Co-authored-by: Thomas <0xtlt@users.noreply.github.com>
Add benches/results/ to .gitignore and point the benchmark README at
locally generated timing files.

Co-authored-by: Thomas <0xtlt@users.noreply.github.com>
@0xtlt
0xtlt marked this pull request as ready for review July 29, 2026 14:24
@cursor

cursor Bot commented Jul 29, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@0xtlt
0xtlt merged commit f8bbc78 into main Jul 29, 2026
2 checks 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.

2 participants