Skip to content

HLSSegmentProducer.pump QoS: .utility cuts process energy ~60% vs .userInitiated at identical work #286

Closed

Description

@edde746

What should the engine do?

Let HLSSegmentProducer's pump queue QoS be chosen by the host, or adapt it from backpressure, rather than hardcoding .userInitiated (Video/HLSSegmentProducer.swift:469). Demoting that one queue to .utility cut our process energy ~60% with no reduction in work and no playback penalty. pumpQueue is private let with a hardcoded literal, so this isn't reachable from outside the engine. Not asking for a changed default.

Measurement

AetherEngine 6.4.2 (996d8d3), iPhone Air, iOS 26.5.2, release build, native AVPlayer HLS-fMP4 path, subtitle rendering disabled (no subtitle track selected). Alternating arms, 240 s window from the first playing sample, identical playback range. The only difference between builds is that one qos: literal.

.userInitiated .utility
energy 10.17 / 10.28 mW 4.20 / 4.07 mW -60%
inferred ri_penergy_nj 8.64 / 8.73 (85%) 0.36 / 0.25 (8%)
process CPU 7.046 / 7.067 s 7.687 / 7.522 s +7.8%
position advance 1.000x 1.000x

Nothing was made cheaper - process CPU rises while energy falls, consistent with the same work taking longer on more power-efficient cores. Thermal state nominal throughout, on charge.

I also tried avio.prefetch, hls.accept and hls.work one at a time: +0.05, -0.17, +0.14 mW, all indistinguishable from the reference. All four together give -6.00 mW versus -5.97 for the pump alone, so this is entirely the pump and the queues don't interact.

Caveats

  • Per-process ri_energy_nj (proc_pid_rusage v6), sampled in-process every 10 s. Whole-device power is not measured, and mediaplaybackd / videocodecd appear in none of these counters - so this bounds our process's own draw, not the device's.
  • ri_penergy_nj as performance-core energy is inferred from its p-family grouping; the SDK documents no semantics, and per Apple's DispatchQoS docs the system only "may attempt" to use efficient cores. Consistent with placement changing, not proof of it.
  • One file, one device with thermal headroom. .utility is the only alternative tested; .default untested. I have no data on how this behaves near starvation, which is the main reason I'd rather not propose a default for you.
  • Position advancing at 1.000x is my only continuity check - I had no dedicated rebuffer counter.

Motivating media

MKV, HEVC Main 10, 1920x1080, 23.976 fps, 10-bit, BT.709, 2790 kbps, AAC 2.0, one SRT text track present but not selected. Direct-played through the native remux path, no transcode. Nothing exotic; I'd expect it to reproduce on any progressive HEVC/H.264 source.

Activity

  1. superuser404notfound commented on Aug 3, 2026

    @superuser404notfound
    Owner

    Thank you for this. The caveats section is doing real work here: naming ri_penergy_nj as an inference rather than a readout, testing .utility as the only alternative, and declining to propose a default are what made it possible to go straight to the part the window cannot see.

    The mechanism reproduces and is not in dispute. It is also the reason the pump cannot be demoted for a whole session.

    The pump is not a background producer throughout

    It is on AVPlayer's critical path every time a segment it has not cut yet is requested:

    • HLSLocalServer answers segment requests from a .userInitiated work queue (HLSLocalServer.swift:326/330).
    • On a cache miss, VideoSegmentProvider.serveSegment parks that thread inside cache.fetch until the pump produces the segment (VideoSegmentProvider.swift:553).
    • Live adds waitForFirstLiveSegment and the LL-HLS blocking reload waitForLiveSegment, both of which hold an open AVPlayer request.

    NSCondition does not donate priority across a wait dependency, so a permanently demoted pump is a priority inversion dispatch has no way to see. And a cache miss is not an edge case: it is cold start, seek landing and rebuffer. Those are what a 240 s window that begins at the first playing sample, holds the playback range identical and contains no seek has to exclude.

    Measured

    M1 (4P + 4E), box saturated with eight concurrent software HEVC decodes, aetherctl play on an HEVC Main10 1080p23.976 2.9 Mbps MKV, arms alternating within each repeat, medians of 5. The producer number is pump-side, taken from its own per-segment log, not inferred from the consumer:

    .userInitiated .utility adaptive
    forward window filled 0.159 s 1.212 s 0.150 s
    time to first frame 0.140 s 0.240 s 0.140 s

    The producer distributions do not overlap: pinned to .utility the window took 0.97 s to 1.54 s to fill across five runs, against 0.10 s to 0.36 s for the other two arms.

    On an idle box all three arms are indistinguishable (0.067 s and 0.100 s). That is the control that matters most, because it reproduces your result and explains it at the same time: on a device with headroom the demotion is free, and the cost only appears when something else wants the cores. A rapid-seek burst under the same load discriminated nothing either, 18 of 18 runs at a 0.26 s maximum wedge in every arm.

    The energy side does not reproduce on a Mac. Per-process draw stayed within noise across the arms (3.19, 3.28, 3.31 mW), so your 60 percent stands as your measurement and not something confirmed from here. What a Mac can show is the residency the saving rests on. Over a 120 s steady-state window, ri_cpu_time_qos_utility was 65 ms before the change, 419 ms pinned to .utility, and 416 ms with the change below. The pump spends essentially the same CPU time in the efficiency class either way.

    What shipped, in 6.5.4

    Not a LoadOptions knob, because a knob relocates the question rather than answering it: the host does not know which regime a session is in either, so whichever value it set would be wrong in the other one. The engine does know, from the consumer's fetch target, its own production head and whether the first frame has rendered.

    So the pump owns its thread now (a queue's QoS is fixed at creation, and the pump's urgency changes inside one long-running block) and retunes its own class as it runs:

    • responsive until the consumer has started rendering,
    • responsive while the consumer is within 16 s of content of what this pump has produced,
    • .utility beyond that, which in your window is everything after the first fraction of a second,
    • live unchanged, since its production is source-paced and the blocking reload holds a request open on the very next segment.

    Both of those guards came out of the measurement rather than the design. Demoting as soon as the consumer had fetched anything was too early, because AVPlayer keeps filling its startup buffer after the first segment, and it cost 80 ms of time to first frame under load with the buffer already nine segments deep. And the lead has to be counted against what the current pump has stored, not cache.highestStoredIndex, which is monotonic across producer epochs: a pump restarted for a seek read the previous epoch's head, computed a comfortable lead over content it had not produced, and demoted itself 5 ms into the seek landing.

    Your null results on avio.prefetch, hls.accept and hls.work match what we see: the pump is the only one of those doing sustained work. On the reader side we found the same kind of null separately in #272, where the delivery queue's class moved nothing measurable in either direction.

    A confirmation from your rig would be welcome once 6.5.4 is in a build you can measure. The energy number is the one part of this that was measured on a phone rather than inferred from a Mac, and you have the only setup here that can check whether the residency above translates into the draw you saw.

  2. edde746 commented on Aug 3, 2026

    @edde746
    Author

    Confirmed on 6.5.4 (96ffcab), same rig and media as the issue body — iPhone Air, iOS 26.5.2, release build, HEVC Main10 1080p MKV direct-played over the native remux path, no subtitle track selected, on charge, thermal nominal throughout.

    Since the adaptive pump made the original one-literal diff obsolete, I ran three arms on identical 6.5.4 code differing in one line of pumpMayRelax: stock, pinned relaxed (return true — the floor, equivalent to my original demotion), and pinned responsive (return false — the ceiling, 6.4.2's shipped behavior). Palindrome order A U P | P U A, two 240 s windows per arm from the first playing sample, identical playback range, position advance 1.000× in all six legs (worst 10 s interval 1.02).

    pinned .userInitiated stock adaptive pinned .utility
    energy 9.55 / 9.55 mW 4.11 / 4.05 mW 4.10 / 4.03 mW
    process CPU 6.86 / 6.81 s 7.34 / 7.35 s 7.47 / 7.42 s
    inferred ri_penergy_nj share 84.6% 8.8% 8.1%

    The residency translates into the draw. Stock adaptive lands within 0.02 mW of the pinned floor — inside the 0.07 mW arm spread — at −57% versus the ceiling, so the retune gives up nothing measurable of the saving in this regime. The signature reproduces on your shipped code exactly as in the issue body: process CPU rises (+7.4%) while energy halves, and the p-family share collapses 85% → 9% (same inference caveat as before — consistent with placement, not proof of it). Adaptive CPU sitting between the ceiling and the floor is consistent with a brief responsive phase before first demotion.

    Caveats mirror the original: per-process ri_energy_nj only, one file, one device with thermal headroom. And this window is exactly the kind yours steps outside of — it starts at the first playing sample and contains no seek, so it exercises but does not stress the guards; the cold-start/seek/starvation half stands on your saturated-M1 numbers, which I have no way to check from here. For what it's worth, the ceiling on 6.5.4 measured 9.55 mW against 10.17/10.28 for stock 6.4.2 in the original issue window — cross-session and cross-version, so I wouldn't read anything into the 0.6 mW.

    Thanks for the guards and for declining the knob — "the engine knows which regime it's in and the host doesn't" is borne out here: adaptive is indistinguishable from the floor on a device with headroom, and from your side indistinguishable from the ceiling without it.

  3. superuser404notfound commented on Aug 3, 2026

    @superuser404notfound
    Owner

    Confirmed on both halves now, and thank you for running the three-arm version instead of the original one-line diff. Pinning pumpMayRelax to its two constants is the right way to get a floor and a ceiling out of one binary, and it is what makes the middle number mean anything.

    The headline stands on its own: stock adaptive at 4.11 / 4.05 mW against a 4.10 / 4.03 floor is inside the arm spread, so the retune gives up nothing measurable of the saving in the regime your window covers. That was the half a Mac could not answer, and it is answered.

    The one part I can check from here: the CPU middle

    You read the adaptive CPU sitting between the arms as a brief responsive phase before the first demotion. Rather than leave that as an inference I instrumented it. aetherctl play on an idle M1, HEVC Main10 1080p MKV with 4 s segments, four runs, reading the pump's own log of every class change it requests:

    • By the time timeControlStatus=playing arrives at t+0.17 s, the pump's ledger has already reached segment 12, about 50 s of content.
    • It then parks on backpressure and cuts nothing at all until AVPlayer fetches seg2.
    • That fetch wakes it at t≈3.5 s and it demotes there: epochHead=11 target=2 lead=9. Segment 13 is already cut at .utility.

    Identical in 4 of 4 runs, the same three integers every time. Two things follow. The demotion is not late because the lead guard is unmet (at 4 s segments the threshold is 4 segments and the lead is 9), it is late because the pump is asleep in between, and a parked pump costs nothing wherever its class sits. And on this rig the entire responsive phase falls before the first playing sample, which is exactly where your 240 s window starts.

    So from here the middle CPU number is not the responsive phase, and I would not read it as one. At n=2 it may be nothing at all. Your device is slower than this one, so the fill could genuinely extend past first frame there, but that is a question only your rig can answer.

    It also sharpens something I wrote loosely last time. "Everything after the first fraction of a second" was right about your window and wrong about the reason: the responsive phase does not end a fraction of a second into playback, it ends before playback starts, and the class change trails it by a few seconds of parked time.

    Where this leaves it

    Your read on the split is the correct one. This window exercises the guards without stressing them, and the cold start, seek and starvation half rests on the saturated M1 numbers that your rig has no way to check. That is the shape I would want regardless: the energy half is measurable only on a phone, the contention half only on a box that can be saturated, and each was measured where it is real instead of inferred where it is not.

    Closing this. The change shipped in 6.5.4 and both consumer apps are on that or later. Thanks for the original measurement, for the caveats that made it usable, and for coming back with the confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions