Skip to content

Stream SSIMULACRA2 in C and upgrade to Zig 0.17 - #7

Merged
gianni-rosato merged 5 commits into
mainfrom
perf/streaming-ssimulacra2-zig-0.17
Oct 24, 2026
Merged

gianni-rosato merged 5 commits into
mainfrom
perf/streaming-ssimulacra2-zig-0.17

Conversation

@gianni-rosato

@gianni-rosato gianni-rosato commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

SSIMULACRA2 currently writes full-frame intermediate planes and reserves scratch proportional to image area. Replace the production Zig implementation with a streaming C pipeline: decode sRGB rows, downsample directly into the next scale, convert only active XYB channels, and retain small row rings. The C loops use compiler vectorization, with no explicit Zig SIMD in the production metric.

On an Apple M5 Pro, the direct filter benchmark is 17–20% faster than the exact vapoursynth-zip 23.0.0 filter at 1080p with 1/8/16 workers and at 4K with one worker. Scratch at 1080p falls to 1.88 MiB per workspace versus upstream's 13.27 MiB, and is independent of height. The existing 4K PAM CLI comparison improves from 173.1 ms / 714.3 MiB to 92.1 ms / 116.0 MiB. x86 throughput has not been measured.

Scores deliberately use float linear samples and a more stable SSIM variance calculation. Identical inputs score exactly 100. Across all 4,341 CID22 pairs, KRCC/SRCC/PCC change from 0.708176/0.891111/0.873170 to 0.708025/0.890985/0.873013, each a difference below 0.0002. The existing PAM pair changes from 70.5898 to 70.5839.

Also migrate the build, translated C imports, Python build requirement, and simpleimgio/libspng/fcvvdp pins to Zig 0.17. Remove the previous Zig implementation and preserve the pre-existing test suite unchanged. The C, Zig, and Python error-map APIs and packed RGBA output remain compatible with existing callers. Zig 0.17 LTO is restricted to ELF targets; macOS now reports an actionable error for that option.

Validation:

  • Native ReleaseFast build passes.
  • Unchanged Python/CLI suite: 15 tests and 6 subtests pass. No new tests are included.
  • Manual error-map checks: a caller compiled against the original C header links successfully; Python uint8/float32 maps preserve shape, packing, strides, score parity, and workspace independence; CLI output is a complete 4K RGBA PAM.
  • ASan/UBSan: small/odd dimensions, workspace reuse, maps, padded rows, unaligned float input, and invalid arguments pass.
  • Cross-builds pass for Linux x86-64/AArch64 and Intel macOS; Linux x86-64 LTO also passes.
  • Complete CID22 correlation run, direct upstream benchmarks, and existing CLI hyperfine comparison completed.

Reproducible benchmark and correlation commands/results are in tests/bench/README.md.

The executable uv script tests/bench/compare_video.py compares both metrics on identical linear RGB video frames and exports per-frame scores and timing.

@gianni-rosato
gianni-rosato merged commit 7d6242b into main Oct 24, 2026
4 checks passed
@gianni-rosato
gianni-rosato deleted the perf/streaming-ssimulacra2-zig-0.17 branch October 24, 2026 19:28
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