Skip to content

Rework resource selection algorithm to avoid interleaved jumps#12502

Open
nicolo-ribaudo wants to merge 1 commit into
whatwg:mainfrom
nicolo-ribaudo:rework-resource-selection
Open

Rework resource selection algorithm to avoid interleaved jumps#12502
nicolo-ribaudo wants to merge 1 commit into
whatwg:mainfrom
nicolo-ribaudo:rework-resource-selection

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo commented May 28, 2026

This is an editorial drive-by change to make it easier to follow the resource selection algorithm when it goes into "children" mode.

Right now this algorithm has four different labeled steps, with other steps that jump to them. These jumps are interleaved with each other (3/4/5/6 -> 10, 14 -> 18, 17 -> 14, 17 -> 2, 26 -> 13), and across either separate synchronized sections or separate parallel sections.

This PR tries to convert it into something simpler to follow. There is some inherent complexity, but I feel like it makes the control flow more clear.

One editorial-but-not-as-trivial change I made is to, instead of waiting "potentially forever" for more <source> elements to be added to the video, normally terminate the algorithm when its done iterating through the <video> children: inserting a new <source> element will then re-trigger it from the steps that keep the pointer up-to-date.

These algorithms have some problems (e.g. #12500), but this PR explicitly tries to leave the problems unchanged.

Also, these algorithms call "await a stable state" while in parallel, but the first step of awaiting a stable state is to enqueue a microtask, which you can only do while not in parallel.

Wishlist for future changes that I might open a PR for:

  • [editorial?] Move the pointer management into the existing insertion/removal/move steps for the <source> element, clarifying the moving ambiguities from Inconsistent cross-browser behavior for mutating child <source>s of a <video> #12500
  • [editorial] Maybe just get rid of this ad-hoc concept of a pointer "between nodes of a list", and instead either use an index or an element (to again keep in sync in the insertion/removal/move steps)
  • [normative?] Do not await for a stable state while in parallel; but probably schedule a task or explicitly grab the right agent and manually schedule a microtask on it.

/media.html ( diff )

@nicolo-ribaudo nicolo-ribaudo added topic: media editorial Changes that do not affect how the standard is understood labels May 28, 2026
@nicolo-ribaudo nicolo-ribaudo force-pushed the rework-resource-selection branch from 8ef1617 to 56db1ae Compare May 28, 2026 17:42
@nicolo-ribaudo nicolo-ribaudo force-pushed the rework-resource-selection branch from 56db1ae to 5ee6502 Compare May 29, 2026 10:13
@annevk annevk requested review from a team and foolip May 29, 2026 12:51
Comment thread source
the node before the pointer and the new node. In other words, insertions at the pointer go
after the pointer.</p></li>

<li><p><span>Await a stable state</span>. The <span>synchronous section</span> consists of all
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably check for NETWORK_NO_SOURCE before awaiting a stable state.

Also, these steps should get aborted on "abort the overall resource selection".

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

Labels

editorial Changes that do not affect how the standard is understood topic: media

Development

Successfully merging this pull request may close these issues.

2 participants