Skip to content

armgit / plexo

Public Imported from GitHub
0

Speed up downloads by combining multiple network connections in parallel

fix: peak speed inflated by bursts measured over a few milliseconds

Anmol Kapil871dcfda7da7
diff --git a/src/main/download/downloadManager.ts b/src/main/download/downloadManager.ts
index dbd8413..d78f132 100644
--- a/src/main/download/downloadManager.ts
+++ b/src/main/download/downloadManager.ts
@@ -112,9 +112,11 @@ function calculateCurrentSpeed(samples: SpeedSample[] | undefined, time: number)
samples.shift()
}
+ // At least a second: a fresh window can hold two samples ms apart, and one socket burst over a
+ // few ms reads as a speed the connection never had (and sticks as the UI's peak).
const oldest = samples[0]
- const deltaSeconds = (time - oldest.time) / 1000
- return deltaSeconds > 0 ? (latest.bytes - oldest.bytes) / deltaSeconds : 0
+ const deltaSeconds = Math.max((time - oldest.time) / 1000, 1)
+ return (latest.bytes - oldest.bytes) / deltaSeconds
}
// Defensive cap independent of whatever the renderer sends — chunks are