@torrent-tv/proxy 2.97.25 → 2.97.26

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.97.25",
3
+ "version": "2.97.26",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
package/server.js CHANGED
@@ -566,7 +566,7 @@ export async function startProxyServer({
566
566
  if (waiting.has(zone.outputKey)) continue;
567
567
  // What is resolved so far is stated before a lower zone is worked out
568
568
  // (DownloadMaps, torrent-tv/meta#178).
569
- map.workingOut?.(zone.priority, expanded());
569
+ map.workingOut?.(zone.priority, expanded);
570
570
  if (direct) {
571
571
  // Asked per zone too: a soundtrack of an AVI is read from its own
572
572
  // packets, which the same index states (torrent-tv/meta#166).
@@ -468,6 +468,8 @@ export function startMemoryReport({
468
468
  /** @type {Record<string, number>} */
469
469
  let lastWritten = {};
470
470
  let lastWrittenAt = 0;
471
+ /** The anonymous memory and the time the mappings were last read at. */
472
+ let mappingsReadAt = null;
471
473
  const slug = (label || scope).replace(/[^a-z0-9]+/gi, "-").toLowerCase();
472
474
  const directory = snapshotDir || os.tmpdir();
473
475
 
@@ -553,13 +555,25 @@ export function startMemoryReport({
553
555
  // the reading now happens once a second rather than once a minute.
554
556
  const available = availableMemory();
555
557
  anonymousBytes = await readAnonymousMemory();
558
+ // THE MAPPINGS ONLY WHERE THE ANONYMOUS MEMORY THEY BREAK DOWN HAS
559
+ // MOVED, or once in a quiet interval. The line is written on every
560
+ // swing of resident memory, which array buffers taken and given back
561
+ // make every two or three seconds, and each walk of `smaps` cost the
562
+ // main thread about 70 ms: 15.6 s of it in ten minutes of a cold AVI
563
+ // on Home Assistant, while segments waited to be sent
564
+ // (torrent-tv/meta#178).
565
+ const mappingsDue = mappingsReadAt === null || now - mappingsReadAt.at >= quietMs ||
566
+ !Number.isFinite(anonymousBytes) || !Number.isFinite(mappingsReadAt.anonymousBytes) ||
567
+ Math.abs(anonymousBytes - mappingsReadAt.anonymousBytes) >= changeBytes;
568
+ const mappings = mappingsDue ? await readMappingSummary() : null;
569
+ if (mappingsDue) mappingsReadAt = { at: now, anonymousBytes };
556
570
  log(describeMemory({
557
571
  scope,
558
572
  label,
559
573
  process: processMemory,
560
574
  available,
561
575
  anonymousBytes,
562
- mappings: await readMappingSummary(),
576
+ mappings,
563
577
  diskFreeBytes: diskPath ? await readDiskFree(diskPath) : null,
564
578
  stores,
565
579
  extra
@@ -87,9 +87,14 @@ export class DownloadMaps {
87
87
  // pass that works nothing out — every pass over a film already worked out
88
88
  // — states nothing early.
89
89
  let stated = Number.POSITIVE_INFINITY;
90
- const workingOut = (priority, zones) => {
90
+ // The zones are asked for only when they are stated: worked out before
91
+ // every lower zone of a pass, they were the whole pass over again at each
92
+ // of its 4000 steps, and a cold AVI's start forecast waited 71 s for it
93
+ // (Home Assistant 2026-10-13, torrent-tv/meta#178).
94
+ const workingOut = (priority, zonesOf) => {
91
95
  if (!(priority < stated)) return;
92
96
  stated = priority;
97
+ const zones = typeof zonesOf === "function" ? zonesOf() : zonesOf;
93
98
  if (zones.length === 0 || !isCurrent()) return;
94
99
  this.#setZones(file, withRetained(zones, retained));
95
100
  this.#emit(file).catch(() => undefined);