@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.
@@ -4290,13 +4290,40 @@ class FileStorage {
4290
4290
  // Empty chunk fast path.
4291
4291
  return new Uint8Array(0);
4292
4292
  }
4293
- // Fetch shards in parallel. Anything missing becomes a placeholder so
4294
- // the decoder can fill it in from the parity shards (up to
4295
- // `parityShards` allowed).
4296
- const fetched = new Array(manifest.shardHashes.length);
4297
- await this.runWithConcurrency(manifest.shardHashes.map((hash, i) => async () => {
4298
- fetched[i] = await this.shards.getShard(hash);
4299
- }));
4293
+ // DATA SHARDS FIRST — parity only if something is actually missing.
4294
+ //
4295
+ // Reed-Solomon needs `dataShards` of the `dataShards + parityShards`
4296
+ // total, and the leading entries are the data ones. Fetching all of them
4297
+ // up front meant every read paid for parity it then threw away: with the
4298
+ // defaults (4 data, 2 parity) that is six round trips where four would
4299
+ // do. It is invisible on one big file and brutal on a project — opening
4300
+ // a 519-file project cost 3,114 shard requests, six per file, most of
4301
+ // them for bytes nobody needed. A file smaller than one shard still
4302
+ // costs its full six, which is why small source modules were the worst
4303
+ // case rather than the best.
4304
+ //
4305
+ // Parity is still fetched, just lazily, so a genuinely damaged chunk
4306
+ // recovers exactly as before — one extra round trip in the rare case
4307
+ // instead of two wasted ones in the common case.
4308
+ const total = manifest.shardHashes.length;
4309
+ const dataCount = Math.max(0, total - manifest.parityShards);
4310
+ const fetched = new Array(total).fill(null);
4311
+ const fetchInto = async (indexes) => {
4312
+ await this.runWithConcurrency(indexes.map((i) => async () => {
4313
+ fetched[i] = await this.shards.getShard(manifest.shardHashes[i]);
4314
+ }));
4315
+ };
4316
+ await fetchInto(Array.from({ length: dataCount }, (_, i) => i));
4317
+ // Only now, and only if a data shard did not arrive, is parity worth
4318
+ // fetching — and then all of it, since we cannot tell which parity
4319
+ // shards the decoder will pick.
4320
+ const missingData = [];
4321
+ for (let i = 0; i < dataCount; i++)
4322
+ if (fetched[i] === null)
4323
+ missingData.push(i);
4324
+ if (missingData.length > 0 && total > dataCount) {
4325
+ await fetchInto(Array.from({ length: total - dataCount }, (_, i) => dataCount + i));
4326
+ }
4300
4327
  const deadIndexes = [];
4301
4328
  const shards = fetched.map((bytes, i) => {
4302
4329
  if (bytes === null) {
@@ -5327,7 +5354,7 @@ function base64UrlDecode(s) {
5327
5354
  * expect (and isn't serving a stale cached bundle). Keep this in sync with
5328
5355
  * `package.json` `version`.
5329
5356
  */
5330
- const VERSION = "0.14.0-alpha.1";
5357
+ const VERSION = "0.14.0-alpha.2";
5331
5358
 
5332
5359
  /**
5333
5360
  * `HttpClient` — the one place the unified {@link Client} talks to the