Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor(reconstruction): keep the second initial block at its usual …
…size

Only the first block sets the time to first byte of a stream, so the
second initial block keeps 2 * min_reconstruction_fetch_size. This avoids
up to two extra reconstruction calls for bounded stream ranges of 258MB
to 1GB, and leaves a single value depending on is_streaming. The reason
for the small first block now lives in the config doc only.
  • Loading branch information
XciD committed Oct 26, 2026
commit 9d234ab4ffb5b4518d91e6968a00a3a064ae0bdb
14 changes: 5 additions & 9 deletions api_changes/update_261026_stream_initial_fetch_size.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
This update makes streamed reconstructions start with small term blocks, so the first bytes of a stream arrive sooner.
Streamed reconstructions now start with a small first term block so the first bytes arrive sooner.

What changed
- Added the config value `reconstruction.stream_initial_fetch_size` (default 2MB, environment variable `HF_XET_RECONSTRUCTION_STREAM_INITIAL_FETCH_SIZE`).
- `ReconstructionTermManager::new` takes a new last argument, `is_streaming: bool`.
- When true, the two initial blocks are `stream_initial_fetch_size` and twice that size, capped at `min_reconstruction_fetch_size`.
- When false, the initial blocks are unchanged (`min_reconstruction_fetch_size` and twice that size).
- `FileReconstructor::run` passes `is_streaming` through, so `reconstruct_to_stream` and `reconstruct_to_unordered_stream` (and the wasm `reconstruct_to_writer`, which streams) use the small initial blocks.
- New config `reconstruction.stream_initial_fetch_size` (default 2MB, `HF_XET_RECONSTRUCTION_STREAM_INITIAL_FETCH_SIZE`), capped at `min_reconstruction_fetch_size`. `reconstruct_to_stream`, `reconstruct_to_unordered_stream` and the wasm `reconstruct_to_writer` use it for their first block.
- `ReconstructionTermManager::new` takes a trailing `is_streaming: bool`.

Why this matters
- A stream yields nothing until its first term is downloaded, and that term can span the whole first block (up to `min_reconstruction_fetch_size`, 256MB by default). With a 67MB first term, a laptop benchmark waited 9 to 27s for the first byte.
- A stream yields nothing until its first term is downloaded, and that term could span a whole 256MB first block.

Usage notes
- Callers of `ReconstructionTermManager::new` must pass `is_streaming`; pass `false` to keep the previous behavior.
- Bounded ranges smaller than about `min_reconstruction_fetch_size` still go in one block: the first block extends to the end of the range when the remainder is below `min_reconstruction_fetch_size`.
- Callers of `ReconstructionTermManager::new` pass `false` to keep the previous behavior.
2 changes: 1 addition & 1 deletion xet_data/src/file_reconstruction/file_reconstructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl FileReconstructor {
/// Runs the file reconstruction with error handling and cancellation support.
/// Returns the number of bytes written.
///
/// When `is_streaming` is true, the first term blocks use `stream_initial_fetch_size`,
/// When `is_streaming` is true, the first term block uses `stream_initial_fetch_size`,
/// and the progress completion assertions at the end of reconstruction are skipped
/// because the stream consumer reports bytes asynchronously after this method returns.
pub(crate) async fn run(
Expand Down
11 changes: 5 additions & 6 deletions xet_data/src/file_reconstruction/reconstruction_terms/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,15 @@ impl ReconstructionTermManager {
// an estimate of the completion time based on the first one. This helps us to get
// a better estimate of the completion time.
//
// A stream returns no data until its first term is downloaded, and that term can span the
// whole first block, so a stream starts with smaller blocks to return its first bytes sooner.
// Only the first block of a stream is smaller, see `stream_initial_fetch_size`.
let min_fetch_size = s.config.min_reconstruction_fetch_size.as_u64();
let initial_fetch_size = if is_streaming {
let first_fetch_size = if is_streaming {
s.config.stream_initial_fetch_size.as_u64().min(min_fetch_size)
} else {
min_fetch_size
};
s.prefetch_block(initial_fetch_size).await?;
s.prefetch_block(2 * initial_fetch_size).await?;
s.prefetch_block(first_fetch_size).await?;
s.prefetch_block(2 * min_fetch_size).await?;

debug!(
%file_hash,
Expand Down Expand Up @@ -246,7 +245,7 @@ impl ReconstructionTermManager {
}

async fn prefetch_block(&mut self, block_size: u64) -> Result<()> {
// No lower bound here: the initial blocks of a stream are smaller than `min_reconstruction_fetch_size`.
// `block_size` can be below `min_reconstruction_fetch_size` for the first block of a stream.
let block_size = block_size.min(self.config.max_reconstruction_fetch_size.as_u64());

// First, check the block range to see if we're over the requested range.
Expand Down
7 changes: 3 additions & 4 deletions xet_runtime/src/config/groups/reconstruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ crate::config_group!({
/// Use the environment variable `HF_XET_RECONSTRUCTION_MAX_RECONSTRUCTION_FETCH_SIZE` to set this value.
ref max_reconstruction_fetch_size: ByteSize = ByteSize::from("8gb");

/// The size of the first fetch request of a streamed reconstruction; the second one is twice this size.
/// A stream returns no data until its first term is downloaded, and that term can span the whole first
/// fetch, so a small first fetch keeps the time to first byte short. Later fetches follow the sizes above.
/// This value is capped at `min_reconstruction_fetch_size`.
/// The size of the first fetch request of a streamed reconstruction, capped at `min_reconstruction_fetch_size`.
/// A stream returns no data until its first term is downloaded, so a small first fetch shortens the time to
/// first byte.
///
/// The default value is 2MB.
///
Expand Down
Loading