Skip to content

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

Open
gianni-rosato wants to merge 4 commits into
mainfrom
perf/streaming-ssimulacra2-zig-0.17
Open

gianni-rosato wants to merge 4 commits into
mainfrom
perf/streaming-ssimulacra2-zig-0.17

Conversation

@gianni-rosato

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. Preserve the previous Zig implementation as a differential-test reference. Zig 0.17 LTO is restricted to ELF targets; macOS now reports an actionable error for that option.

Validation:

  • Native ReleaseFast build and zig build test --release=fast pass.
  • Python/CLI suite: 19 tests and 6 subtests pass.
  • 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.

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