Skip to content

Add CodSpeed performance benchmarks - #1

Merged
taskylizard merged 2 commits into
trunkfrom
codspeed-wizard-1786543870444
Aug 12, 2026
Merged

Add CodSpeed performance benchmarks#1
taskylizard merged 2 commits into
trunkfrom
codspeed-wizard-1786543870444

Conversation

@codspeed-hq

@codspeed-hq codspeed-hq Bot commented Aug 12, 2026

Copy link
Copy Markdown

Sets up continuous performance measurement with CodSpeed for the rendering pipeline.

What was added

benches/ — 16 divan benchmarks (via codspeed-divan-compat, renamed to divan), split into three suites. They live in the root crate because that is where the shipped templates, example photos and fonts are; maple-render-core deliberately bundles none of them, and the benchmarks exercise its public API through the maple re-exports.

  • render.rs — template archive parsing (open_template), PNG layer decoding (decode_frame_layers), frame compositing in both qualities (composite_sampled, composite_simple, composite_multi_layer), the downscale/letterbox pass (composite_scaled) and the point-cloud scan behind --auto_zoom (frame_cloud).
  • quantize.rs — median-cut palette construction (build_palette) and palette mapping with a cold cache, a warm cache and Floyd-Steinberg dithering, which is what each animation frame goes through.
  • pipeline.rs — the end-to-end work of a real invocation: full animated GIF with and without dithering, GIF serialization on its own, JPEG input decoding and text-layer rasterization.

.github/workflows/codspeed.yml — runs on pushes to trunk/main, on pull requests and on workflow_dispatch, using CodSpeedHQ/action@v5 in simulation mode with OIDC authentication. It follows the existing CI conventions (actions/checkout@v4, dtolnay/rust-toolchain@stable, Swatinem/rust-cache@v2).

Cargo.toml — a codspeed profile inheriting release, with debug symbols kept for readable flame graphs and panic = "unwind", because a benchmark harness cannot be built with the panic = "abort" of the release profile.

README.md — CodSpeed badge and a short section on running the benchmarks locally.

Two things worth knowing

  • -C target-cpu=native and the CPU simulator. .cargo/config.toml builds with target-cpu=native; on these runners that emits AVX-512 instructions the simulator cannot execute (the first local run died with SIGILL). The workflow therefore sets RUSTFLAGS: -C target-cpu=x86-64-v3, which keeps AVX2-era codegen and has the side benefit of making measurements comparable across machines.
  • rayon determinism. The compositor parallelizes rows with rayon, whose worker count and work splitting vary per machine and add noise. The benchmarks default to RAYON_NUM_THREADS=1 (set in benches/common/mod.rs, overridable from the environment) and warm the pool once before measuring, so lazy pool initialization stays out of the first measured iteration.

Verified locally

codspeed run --mode simulation -- cargo codspeed run measured all 16 benchmarks with profiling data for each, in about 45 seconds. cargo fmt --check, cargo clippy --locked --all-targets -- -D warnings and cargo test --locked --lib all pass with the new files.

Next steps

  • Merge to trunk so CodSpeed records a baseline; later pull requests then get a comparison against it.
  • Optional additions later: WebP encoding (webp_anim, behind the default webp feature) and the --vid path, which needs ffmpeg on the runner.

@codspeed-hq

codspeed-hq Bot commented Aug 12, 2026

Copy link
Copy Markdown
Author

Congrats! CodSpeed is installed 🎉

🆕 20 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

Detected benchmarks


Open in CodSpeed

@codspeed-hq
codspeed-hq Bot marked this pull request as ready for review August 12, 2026 14:49
@codspeed-hq
codspeed-hq Bot requested a review from taskylizard August 12, 2026 14:51
@taskylizard

Copy link
Copy Markdown
Collaborator

@codspeedbot Can you add webp encoding benches as well?

@codspeed-hq

codspeed-hq Bot commented Aug 12, 2026

Copy link
Copy Markdown
Author

@codspeedbot Can you add webp encoding benches as well?

Added a webp suite — 4 new benchmarks in benches/webp.rs, bringing the total to 20. Measured values from a local codspeed run --mode simulation run:

Benchmark Simulated time What it covers
webp_animation 769.8 ms full --webp output: every frame composited and handed to libwebp (lossy, quality 95, method 4)
webp_serialize 496.6 ms libwebp encoding on its own, with all frames composited before measuring — the counterpart of gif_serialize
webp_single_frame 45.0 ms one still frame, the --webp_single path
webp_single_frame_lossless 707.6 ms the same frame with --webp_lossless

Notes on a couple of choices:

  • No full lossless animation. I measured one first: 6.87 s of simulated time, which alone took longer than the rest of the suite put together (total run went from 45 s to over 5 min). Since webp_single_frame_lossless already exercises the lossless encoder, I dropped the animated variant; the whole suite now runs in about 1 min 50 s under the simulator.
  • webp_serialize needs pre-composited frames. Renders composites lazily on first access, so encoding-only measurement would otherwise include the compositing work. Added a common::warm_renders helper that walks every frame before the measured section.
  • webp_anim is native-only and not re-exported by maple, so the suite imports it from maple_render_core directly — no change to the library's public API.

cargo fmt, cargo clippy --locked --all-targets -- -D warnings and cargo test --locked --lib all pass, and all 20 benchmarks are measured with profiling data. The PR description has been updated accordingly.

Summary
  • Warming up the performance wizard...
  • Exploring the repository — Read the existing benchmarks and the WebP encoding code paths
  • Adding WebP encoding benchmarks — Added benches/webp.rs with 5 benchmarks; clippy and fmt pass
  • Measuring the new benchmarks — All 20 benchmarks measured in simulation mode; the WebP suite adds ~1 min of CI time
  • Committing and updating the pull request — Pushed benches/webp.rs with 4 WebP encoding benchmarks to the pull request
  • Handling comment — Comment handling finished successfully

Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot.

Adds benches/webp.rs covering the --webp and --webp_single paths: the full
animated WebP encode, libwebp serialization of already composited frames, and
single-frame lossy and lossless encoding.
@taskylizard
taskylizard merged commit 5d9a6df into trunk Aug 12, 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