Skip to content

perf: build x264 with patches that skip unchanged macroblocks - #116

Merged
DarrenBaldwin07 merged 2 commits into
mainfrom
tembo/x264-skip-unchanged-macroblocks
Nov 19, 2026
Merged

DarrenBaldwin07 merged 2 commits into
mainfrom
tembo/x264-skip-unchanged-macroblocks

Conversation

@DarrenBaldwin07

@DarrenBaldwin07 DarrenBaldwin07 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Ports the x264 work Ryan Kuba (thelamer) linked in #66 (pixelflux 8483a53) to voxl, and adds two fixes it needed.

voxl already gives x264 a per-macroblock "unchanged" map from X damage (mb_info). Stock x264 still copies the whole input frame, filters the whole lowres picture, and loads and analyses every macroblock, so on a 2560×1600 screen a frame where a small window moved costs nearly as much as a full-screen change. These patches make x264 skip that work for macroblocks marked unchanged. The output is the same bitstream; only the encode time changes.

stock vs patched x264

2560×1600, 60 fps loadgen, 4 encoder threads encode / frame voxl CPU latency p50
480×270 window 6.2 → 3.9 ms (−38%) 1.02 → 0.69 cores (−32%) 9 → 7 ms
1080p window 8.0 → 7.4 ms (−7%) 1.49 → 1.38 cores (−7%) 15 → 14 ms
Full screen 8.8 → 8.9 ms (no change) 1.79 → 1.79 cores 17–19 ms both

These are means of 4–10 alternating runs of the same voxl binary with stock or patched libx264.so on a 16 vCPU AMD EPYC 9334 VM. Bitrate and FPS are the same with both. voxl's own encode_cost bench (a 640×360 change, hints on) drops from 6.3–6.9 to 3.2–3.6 ms wall and from 15–16 to 8–9 ms of CPU per frame. Stock x264 barely gains from the hints (6.6 vs 6.9 ms); with the patches they halve the cost.

Changes

  • patches/x264/0001–0004: pixelflux's patches 2–5, unchanged apart from the numbering in their subjects. They apply cleanly to nixpkgs' x264 (373697b, the version voxl already builds with):
    • code macroblocks marked constant as P_SKIP in the slice loop, without loading or analysing them, wherever x264's mb_info fast skip would
    • copy only the input macroblocks that changed into x264's recycled input frame, or the whole frame when more than half changed
    • filter only the lowres blocks whose input changed
  • patches/x264/0005: fix. Under VBV at an emergency QP (above 51), x264's fast skip compares against the QP after it's clamped to 51, so it never takes the skip there. The patch compared against the unclamped QP and coded P_SKIP where stock x264 codes P_L0, so the stream no longer matched stock. The voxl config hits this with its 1.25-frame VBV buffer. The patch now compares against the clamped QP.
  • patches/x264/0006: fix, crash. The changed-macroblock copy widened luma runs to 32 bytes for x264's SIMD plane_copy. On CPUs with AVX-512 that resolves to x264_plane_copy_avx512, which stores 64-byte aligned and ends each row with a full 64-byte store. The result was a SIGSEGV on the first hinted frame where a change started on an odd macroblock pair, and it could also have zeroed input pixels after a run. Runs now widen to 4 macroblocks (64 bytes); pixelflux was tested on a Zen 3, which has no AVX-512. Pixelflux carries the same bug upstream.
  • x264.nix applies them to nixpkgs' x264, and default.nix (which the Computer preview builds) and shell.nix (dev and CI) use it.
  • No Rust changes. The patches add no API, so cargo install against a system x264, macOS (brew) and Windows (vcpkg) build and behave as before, just without the savings.

Verification

  • Bit-exact vs stock x264 (nix builds, same toolchain) on 75 deterministic configurations, all identical:
    • scenes: typing, 480×270 / quarter / 1080p animated windows, full screen, scroll, and a mixed run with CRF 16 paint-overs, rate reconfigs, a mid-stream IDR and frames without hints
    • sizes: 2560×1600, 1920×1080, 1366×770, 1280×720
    • modes: 1 thread CRF, 1 thread VBV, 4 sliced threads CRF
    • Before 0005, VBV runs differed. Before 0006, 30 of the 60 configurations then tested segfaulted on this AVX-512 VM.
  • 4 sliced threads + VBV, the mode voxl runs in production, isn't reproducible run to run even with stock x264. For it I checked that ffmpeg's decode of the stream matches x264's own reconstruction (psz_dump_yuv) frame for frame, with both libraries and 4 scenes, so the decoder doesn't drift.
  • cargo test --release passes against the patched x264. nix-build of default.nix links it. oxfmt and alejandra are clean.

Full suite (suite.sh + cpusuite.sh)

Three interleaved reps of voxl's suite, plus two of cpusuite.sh, with patched and stock x264 under the same voxl binary, on a 16 vCPU EPYC 9334 like the README's. The README's voxl column and CPU row now come from the patched runs (best of three, as before).

Test patched, best stock, best median p50, patched / stock
Chromium scroll, LAN 60.0 (58.1), 37/50 ms 60.1 (59.7), 54/62 ms 54 / 56 ms
Scroll, 10 Mbps / 40 ms 60.1 (59.6), 80/90 ms 60.1 (59.5), 81/91 ms 96 / 81 ms
Scroll, 5 Mbps / 60 ms 60.0 (59.2), 98/115 ms 60.1 (59.2), 98/112 ms 99 / 99 ms
1080p animation, LAN 60.0 (59.8), 13/18 ms 60.0 (58.1), 13/23 ms 13 / 14 ms
Animation, 10 Mbps / 40 ms 60.0 (58.1), 45/72 ms 59.9 (57.9), 45/102 ms 45 / 46 ms
Animation, 5 Mbps / 60 ms 60.0 (59.4), 60/84 ms 60.1 (59.6), 61/78 ms 61 / 61 ms
Full-screen animation, LAN 60.0 (59.4), 16/23 ms 59.9 (58.2), 16/26 ms 16 / 17 ms

CPU, voxl + Xvfb (mean of 2): patched 0.00 / 1.54 / 1.44 / 2.00 cores (idle / 1080p / scroll / full screen), stock 0.00 / 1.56 / 1.52 / 1.94.

On these workloads the two are within run-to-run noise. The suite changes large areas every frame (a 1600×950 browser window, a 1080p window, the whole screen), where the patches save little; the savings show on smaller changes (the table above). Scroll latency moves in whole-frame (~17 ms) steps between runs with either library, from Chromium's frame pipeline, so the 37 ms scroll best is a lucky run, not the patches. Both libraries measured more CPU in this session than the README's previous voxl row (1.39 / 1.33 / 1.68), so the README now says voxl's numbers come from a later session than the other servers'.

Follow-ups (not in this PR)

  • The Computer preview pins voxl at v0.3.5 in the monorepo flake, so it picks this up after a release and a bump.
  • The CLI's static Linux build (apps/cli/build-linux-libs.sh in the monorepo) builds x264 itself; it'd need to apply patches/x264 too.
  • 0005 and 0006 could go back to pixelflux.

Want tembo to make any changes? Add a comment with @tembo and i'll get back to work!

View on Tembo  Review in Tembo  View Agent Settings  View on slack

@tembo tembo Bot added the tembo Pull request created by Tembo label Nov 19, 2026
@DarrenBaldwin07
DarrenBaldwin07 merged commit db62434 into main Nov 19, 2026
10 checks passed
DarrenBaldwin07 added a commit that referenced this pull request Nov 19, 2026
## What

Bumps voxl from 0.3.5 to 0.4.0 in `Cargo.toml`, `Cargo.lock` and
`default.nix`. Once this merges, pushing the `v0.4.0` tag on the merge
commit publishes the crate to crates.io and creates the GitHub release,
with generated notes and the crate attached (`release.yml`).

Changes since the `v0.3.5` tag:

- perf: build x264 with patches that skip unchanged macroblocks (#116)
- feat(web): add a trackpad mode for touch screens (#115)
- build: declare rust-version 1.86, the Rust the Linux CI job builds
with (#107)

The `v0.3.5` tag points at #99 (the optional `pulseaudio` feature), so
that change is already in 0.3.5 and isn't repeated here.

## Testing

- `cargo metadata --locked` passes, so `Cargo.lock` matches
`Cargo.toml`.
 
  


 <br /> 


> Want tembo to make any changes? Add a comment with `@tembo` and i'll
get back to work!


<a
href="https://app.tembo.io/sessions/75ad8969-8072-458a-973b-b4f3cec3bbac"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://internal.tembo.io/static/view/tembo-dark.png?v=3"><source
media="(prefers-color-scheme: light)"
srcset="https://internal.tembo.io/static/view/tembo-light.png?v=3"><img
alt="View on Tembo"
src="https://internal.tembo.io/static/view/tembo-light.png?v=3"
width="134" height="28"></picture></a>&nbsp;&nbsp;<a
href="https://app.tembo.io/reviews/redirect?sessionId=75ad8969-8072-458a-973b-b4f3cec3bbac"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://internal.tembo.io/public/tembo-button/review?theme=dark&v=3"><source
media="(prefers-color-scheme: light)"
srcset="https://internal.tembo.io/public/tembo-button/review?theme=light&v=3"><img
alt="Review in Tembo"
src="https://internal.tembo.io/public/tembo-button/review?theme=light&v=3"
width="145" height="28"></picture></a>&nbsp;&nbsp;<a
href="https://app.tembo.io/settings/models"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://internal.tembo.io/public/agent-button/claudeCode:claude-opus-5-5:xhigh?theme=dark&v=12"><source
media="(prefers-color-scheme: light)"
srcset="https://internal.tembo.io/public/agent-button/claudeCode:claude-opus-5-5:xhigh?theme=light&v=12"><img
alt="View Agent Settings"
src="https://internal.tembo.io/public/agent-button/claudeCode:claude-opus-5-5:xhigh?theme=light&v=12"
height="28"></picture></a>&nbsp;&nbsp;<a
href="https://tembo-io.slack.com/archives/C08S9PXF1KJ/p1795122498696389"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://internal.tembo.io/public/vendor-button/slack?theme=dark&v=2"><source
media="(prefers-color-scheme: light)"
srcset="https://internal.tembo.io/public/vendor-button/slack?theme=light&v=2"><img
alt="View on slack"
src="https://internal.tembo.io/public/vendor-button/slack?theme=light&v=2"
height="28"></picture></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tembo Pull request created by Tembo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant