@muhkoo/connect 0.14.0-alpha.1 → 0.14.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3235,7 +3235,7 @@ function base64UrlDecode(s) {
3235
3235
  * expect (and isn't serving a stale cached bundle). Keep this in sync with
3236
3236
  * `package.json` `version`.
3237
3237
  */
3238
- const VERSION = "0.14.0-alpha.1";
3238
+ const VERSION = "0.14.0-alpha.2";
3239
3239
 
3240
3240
  /**
3241
3241
  * `HttpClient` — the one place the unified {@link Client} talks to the
@@ -7701,13 +7701,40 @@ class FileStorage {
7701
7701
  // Empty chunk fast path.
7702
7702
  return new Uint8Array(0);
7703
7703
  }
7704
- // Fetch shards in parallel. Anything missing becomes a placeholder so
7705
- // the decoder can fill it in from the parity shards (up to
7706
- // `parityShards` allowed).
7707
- const fetched = new Array(manifest.shardHashes.length);
7708
- await this.runWithConcurrency(manifest.shardHashes.map((hash, i) => async () => {
7709
- fetched[i] = await this.shards.getShard(hash);
7710
- }));
7704
+ // DATA SHARDS FIRST — parity only if something is actually missing.
7705
+ //
7706
+ // Reed-Solomon needs `dataShards` of the `dataShards + parityShards`
7707
+ // total, and the leading entries are the data ones. Fetching all of them
7708
+ // up front meant every read paid for parity it then threw away: with the
7709
+ // defaults (4 data, 2 parity) that is six round trips where four would
7710
+ // do. It is invisible on one big file and brutal on a project — opening
7711
+ // a 519-file project cost 3,114 shard requests, six per file, most of
7712
+ // them for bytes nobody needed. A file smaller than one shard still
7713
+ // costs its full six, which is why small source modules were the worst
7714
+ // case rather than the best.
7715
+ //
7716
+ // Parity is still fetched, just lazily, so a genuinely damaged chunk
7717
+ // recovers exactly as before — one extra round trip in the rare case
7718
+ // instead of two wasted ones in the common case.
7719
+ const total = manifest.shardHashes.length;
7720
+ const dataCount = Math.max(0, total - manifest.parityShards);
7721
+ const fetched = new Array(total).fill(null);
7722
+ const fetchInto = async (indexes) => {
7723
+ await this.runWithConcurrency(indexes.map((i) => async () => {
7724
+ fetched[i] = await this.shards.getShard(manifest.shardHashes[i]);
7725
+ }));
7726
+ };
7727
+ await fetchInto(Array.from({ length: dataCount }, (_, i) => i));
7728
+ // Only now, and only if a data shard did not arrive, is parity worth
7729
+ // fetching — and then all of it, since we cannot tell which parity
7730
+ // shards the decoder will pick.
7731
+ const missingData = [];
7732
+ for (let i = 0; i < dataCount; i++)
7733
+ if (fetched[i] === null)
7734
+ missingData.push(i);
7735
+ if (missingData.length > 0 && total > dataCount) {
7736
+ await fetchInto(Array.from({ length: total - dataCount }, (_, i) => dataCount + i));
7737
+ }
7711
7738
  const deadIndexes = [];
7712
7739
  const shards = fetched.map((bytes, i) => {
7713
7740
  if (bytes === null) {