github selkies-project/selkies ce9fbb3

latest releases: e109961, ea58b37, 6959b7c...
pre-release10 days ago

perf(pixelflux): Convert a frame's bands on a pool of as many threads (#559)

A software session converts each frame to YUV in as many bands as its
encode threads, up to eight for libvpx, x265 and SVT-AV1 and four for
x264, and handed the bands to rayon's global pool, which has a thread per
CPU. The pool also woke the threads it had no band for, every frame, and
they spun before they slept again. On a 16-thread host streaming x264 at
57 fps, twelve threads took 136-1,100 involuntary context switches a
second each, and the server took 174 context switches and 8.0 ms of CPU
a frame.

The conversions now run on a pool of as many threads as bands, one for
each band count, built on first use and kept for the process. A count
over 16, or a pool that cannot be built, falls back to the global pool.
A conversion called on a rayon thread keeps to that thread's pool, as
the forked encoder probe needs: a pool built before the fork has no
threads in the child. The striped JPEG path keeps the global pool.

Against main's release build at 1280x720, in interleaved runs, x264
takes 9-11 % less CPU and 61-77 % fewer context switches a frame on a
motion scene, at 57 fps over WebSockets and uncapped over both
transports, and its uncapped rate over WebRTC is 2 % higher (8 of 8
pairs). With the
scene's noise band at 57 fps it takes 7-8 % less CPU a frame over both
transports, and its latency through the page does not change. VP9 and
AV1, at eight bands, take 47-69 % fewer context switches and 4-8 % less
CPU a frame. VP8, which converts in one band, is unchanged.

Two x264 displays at 1280x720, both converting in four bands on the one
pool, keep each display's frame rate and latency within main's runs,
with less CPU a frame in every pair.

Don't miss a new selkies release

NewReleases is sending notifications on new releases.