Repository navigation
perf(avio): the persistent window holds the delivered chunks, so a trim copies nothing (AE#619) - #620
Merged
Merged
Conversation
…im copies nothing (AE#619) trimWindowLocked dropped the consumed head with window.subdata(in:), which copied everything still ahead of the cut into a fresh buffer: up to ~18 MB once per 4 MB consumed, and each append after it grew that fresh buffer by reallocation. The window is now a ChunkedByteWindow that keeps the Data chunks as the connection delivered them. A trim advances an offset and releases the chunks it passed. A truncate for a reconnect slices one chunk. Reads copy out of the chunks into the AVIO buffer, which they did before as well. winStart, the lookback and every count the reader reports are unchanged. Measured with release aetherctl on an M1 Air, one FFmpeg-muxed 4K HEVC + AC-3 5.1 fixture at 91.6 Mbit/s over Scripts/slowrange.py (1 Gbit/s, 20 ms), process CPU over seconds 20 to 110 of 120 s sessions, arms alternated: software 8710a24 0.208 / 0.203 / 0.207 this 0.202 / 0.203 / 0.205 native 8710a24 0.167 / 0.165 / 0.167 this 0.160 / 0.166 / 0.164 About -0.003 cores on both routes, inside the spread of the arms: the change is not separable from noise in process CPU. What it removes is visible in a 20 s sample of the software route: trimWindowLocked 35 -> 0 samples, appendPersistentData 13 -> 1, _platform_memmove 205 -> 140. No rebuffer on any run. Tests: ChunkedByteWindow against a contiguous Data reference over 5000 random appends, reads, drops and truncates, plus edge cases and a pin that a drop keeps the storage of what remains. A reader-level test reads 12 MB forward and 256 KB back inside the lookback from a patterned origin and checks every byte and that the backward read made no request. ThrottledOriginServer gains an opt-in patterned body for it. 3388 swift-testing and 629 XCTest tests green. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_014AVNwe8YDG9EQM7uHdjT3f
This was referenced Sep 24, 2026
Closed
brandomoore
pushed a commit
to brandomoore/AetherEngine
that referenced
this pull request
Sep 24, 2026
…re and peak footprint Regenerated from aetherengine-bench's 2026-09-24 session on 7.15.2. Every engine now plays each file from disk and over HTTP from a range origin at 1000 Mbit/s and 20 ms, at 38 and 90 Mbit/s, with a peak footprint column. The previous block was measured with 6.26.0, from disk only, and could not show what superuser404notfound#620 changed in the HTTP reader. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_014AVNwe8YDG9EQM7uHdjT3f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #619.
What
AVIOReader's persistent window is now aChunkedByteWindow, which keeps theDatachunks the connection delivered.trimWindowLocked()copied everything ahead of the cut (up to ~18 MB) once per 4 MB consumed, and each later append grew the fresh buffer by reallocation.winStart, the lookback, and every count the reader reports are unchanged.Measured, honestly small
Setup: release
aetherctlon an M1 Air, a 4K HEVC + AC-3 5.1 fixture at 91.6 Mbit/s, served byScripts/slowrange.pyat 1 Gbit/s with 20 ms latency. Process CPU is counted over seconds 20 to 110 of 120 s sessions, with the arms alternated.8710a245That is about -0.003 cores on both routes, inside the spread of the arms, so process CPU cannot tell the change apart from noise. My estimate in #619 (~0.01 core) was read off profile shares and was too high.
What the change removes does show in a 20 s
sampleof the software route:8710a245trimWindowLockedappendPersistentData_platform_memmoveNo run of either arm rebuffered.
Memory, which is what this is worth
Peak memory from
/usr/bin/time -l, 45 s sessions on the same fixture and origin, three runs per arm, arms alternated:8710a245peak footprintMax RSS moves the same way (software 492 to 537 MB -> 217 to 229 MB, native 791 to 890 MB -> 546 to 568 MB). That is roughly 420 MB less on the software route and 330 MB less on the native one, with no overlap between the arms. The saving is far larger than the transient double buffer of a single trim. The old path allocated a fresh ~12 to 18 MB buffer on every trim and then grew it by reallocation on every append, and the allocator evidently kept much of that churn resident. I did not trace which allocator path holds it. On an Apple TV 4K (3rd gen, 3.88 GB RAM) this is the change that matters, not the CPU.
Tests
ChunkedByteWindowis checked against a contiguousDatareference over 5000 random appends, reads, drops and truncates. There are also edge cases (empty, slices, a partly consumed chunk, truncation on and inside a chunk edge), and a pin that a drop keeps the storage of what remains.ThrottledOriginServergains an opt-inpatternedBodyfor this; its default is unchanged.🤖 Generated with Claude Code
https://claude.ai/code/session_014AVNwe8YDG9EQM7uHdjT3f