Skip to content

Live HLS: fragment objects accumulate for the whole session, and the per-second loops walk every hole #211

Closed

Description

@Nawid3333

Severity: low

Where: chrome/player/players/hls/HLSPlayer.mjs (trackUpdated: if (!this.client.getFragment(identifier, fragment.sn)) makeFragment(...); nothing deletes entries whose sn has left the live window), chrome/player/FastStreamClient.mjs (freeFragments drops only the data of complete fragments; the store is a sparse array indexed by media sequence number, and for (let i = 0; i < fragments.length; i++) loops run every second)

What happens

A stream watched for hours keeps one HLSFragment plus the hls.js Fragment (stats, elementary-stream info, key references) per segment ever listed: about 1-2 KB x 1,800 per hour for 2 s segments, and the per-second loops grow linearly; a 24 h session is tens of MB and millions of empty iterations per tick.

Suggested fix

In trackUpdated, after walking levelDetails.fragments, delete store entries with sn < levelDetails.fragments[0].sn - keepBehind (calling freeFragment first), or switch the per-level store to a Map keyed by sn and iterate its values.

Confidence: high on the growth; medium on practical impact.


From a line-by-line code review of the tree at 41363fd (2026-10-02). Each claim above was checked against the source before filing; the reproduction steps and line references are as of that commit.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-reviewFound by the 2026-10-02 line-by-line reviewenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions