Skip to content

Feature Request: Make HTTPDiscIOReader reuse AetherEngine.prewarm cache #647

Closed

Description

@ijuniorfu

What should the engine do?

Summary

AetherEngine.prewarm() currently prefetches the beginning of an HTTP resource into memory, but HTTPDiscIOReader maintains its own independent buffer and does not appear to reuse the prewarmed data.

As a result, when opening a remote ISO/BDMV/DVD image over HTTP, the same beginning bytes may be requested again by HTTPDiscIOReader.

It would be useful if HTTPDiscIOReader could reuse data already fetched by AetherEngine.prewarm().

Current Behavior

The current flow is roughly:

AetherEngine.prewarm(url, byteBudget:)
        │
        ├── fetch opening bytes
        └── keep them in the prewarm cache
                 
Later:

HTTPDiscIOReader(url)
        │
        ├── creates its own buffer
        └── performs its own HTTP Range requests

The two caches are independent.

For example, if:

await AetherEngine.prewarm(
    url: url,
    httpHeaders: headers,
    byteBudget: 10 * 1024 * 1024
)

has already fetched the first 10 MiB, HTTPDiscIOReader may still issue a new Range request for data near byte 0 instead of consuming the already available bytes.

This creates unnecessary network traffic and increases startup latency.

Proposed Behavior

Allow HTTPDiscIOReader to consume the existing AetherEngine.prewarm data when the URL and relevant HTTP request parameters match.

For example:

AetherEngine.prewarm()
        │
        ▼
Opening-byte cache
        │
        │ shared
        ▼
HTTPDiscIOReader
        │
        ├── read(0...)
        ├── seek(...)
        └── continue from warm frontier

Ideally, the reader should:

  1. Check whether prewarmed data exists for the requested URL.
  2. Reuse the cached opening bytes for reads covered by the prewarm range.
  3. Avoid issuing duplicate HTTP Range requests for already cached bytes.
  4. Continue fetching from the end of the prewarmed range when the requested offset exceeds the cached range.
  5. Preserve the existing adaptive read-ahead behavior of HTTPDiscIOReader.

Example

With:

await AetherEngine.prewarm(
    url: url,
    httpHeaders: headers,
    byteBudget: 10 * 1024 * 1024
)

the following should ideally happen:

HTTP resource

0 ─────────────────────────────── 10 MiB ────────────────>
│             prewarmed data       │
│             already in RAM       │
└──────────────────────────────────┘
                                   ↑
                              warm frontier

HTTPDiscIOReader:

read(0, ...)
    → serve directly from prewarm cache

read(1 MiB, ...)
    → serve directly from prewarm cache

read(8 MiB, 10MiB)
    → serve directly from prewarm cache

read(10 MiB+, ...)
    → HTTP Range request starting from/around warm frontier

Why This Matters

Remote disc images can require multiple reads during initialization and navigation.

For HTTP ISO/BDMV/DVD playback, avoiding duplicate requests for the opening bytes could reduce:

  • startup latency
  • redundant network traffic
  • HTTP request count
  • initial buffering overhead

It would also make AetherEngine.prewarm() useful for both normal HTTP media and HTTPDiscIOReader-based media.

Compatibility

This should be backward compatible.

If no prewarm data is available, HTTPDiscIOReader should continue using its existing buffering and adaptive read-ahead implementation exactly as it does today.

Suggested Acceptance Criteria

  • HTTPDiscIOReader can reuse compatible AetherEngine.prewarm() data.
  • Reads within the prewarmed range do not trigger duplicate HTTP requests.
  • Reads beyond the prewarmed range continue normally.
  • Existing adaptive read-ahead behavior remains unchanged.
  • seek() continues to work correctly.
  • No significant increase in memory usage beyond the requested byteBudget.

Environment

  • AetherEngine
  • HTTPDiscIOReader
  • Remote HTTP(S) ISO/BDMV/DVD playback
  • AetherEngine.prewarm()

Related Files

  • Sources/AetherEngine/IO/HTTPDiscIOReader.swift
  • AetherEngine.prewarm() implementation

I believe sharing the prewarm opening-byte cache with HTTPDiscIOReader would make remote disc-image startup more efficient while preserving the current reader architecture.

Motivating media or use case

none

Area

Codec / container support

Host app / integration context

No response

Would you be willing to open a PR?

No

Activity

  1. added
    enhancement
    on Sep 26, 2026
  2. superuser404notfound commented on Sep 26, 2026

    @superuser404notfound
    Owner

    Thanks for the detailed report. The diagnosis was right: HTTPDiscIOReader never looked at the prewarm store. A warmed .iso still probed its size with bytes=0-0 and fetched the head again, and the warm stayed unused in the store.

    This is fixed on main in #648 (merge 6bc0d889) and will ship in the next release. What changes:

    • The disc reader adopts the warm under the same rule the streaming reader uses. The URL and the request headers must match, and the warm must start at byte zero and state the total size.
    • The warm's size replaces the range probe. Reads inside the warmed bytes are served from memory, and the first HTTP request starts at the warm frontier. The adaptive read-ahead continues from there as a sequential read.
    • Forks of the reader (the subtitle side reader, the forward prefetcher) share the same bytes without a copy and no longer re-probe the size.
    • A disc-image URL that turns out not to be a disc hands the warm to the streaming reader it falls back to, so nothing is wasted.
    • Memory stays bounded by byteBudget. The adopting reader holds the warm, and the store no longer keeps a second copy.

    Measured with aetherctl play --prewarm on an authored DVD ISO (49 MB) behind a range origin with 20 Mbit/s and 100 ms per response:

    requests after the warm first frame
    before, warmed 19 (warm unused) ~29 s
    after, warmed 10, first one at the frontier 23.9 s

    One limit: the reader does not pin the warm's redirect target. It follows redirects per request, as it did before.

    Most of the remaining startup time is a separate issue. MPEG-PS (DVD VOB) never lets find_stream_info finish early, so every DVD open reads the full probe budget. I'm opening a separate issue for it.

    A retest against your own server would be very welcome once the release is out.

  3. superuser404notfound commented on Sep 26, 2026

    @superuser404notfound
    Owner

    Released in 7.18.0 (da2b4504).

  4. ijuniorfu commented on Sep 27, 2026

    @ijuniorfu
    Author

    It is simply incredible—the start time of the first frame is more than ten times faster with a prewarm

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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions