Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move worklets into the HTML Standard #6056

Merged
merged 12 commits into from
Oct 16, 2020
Merged

Move worklets into the HTML Standard #6056

merged 12 commits into from
Oct 16, 2020

Conversation

domenic
Copy link
Member

@domenic domenic commented Oct 12, 2020

Closes w3c/css-houdini-drafts#1000.

This provides a baseline by porting over all the existing text from
https://drafts.css-houdini.org/worklets/#lifetime-of-the-worklet,
modernizing and restructuring it along the way. It does not yet fix many
of the open logged issues (although it does fix some; see below).

Notable changes from that document:


This PR has three TODOs in the source:

  • The credentials mode is missing from one call site of "fetch a worklet script graph". This is a preexisting problem, and probably we can survive with this and merge it. (I made it an XXX.) I think doing this properly might involve converting the module responses map from url-keyed to (url, credentials mode) keyed? I'll want to research what implementations do...

  • The "cross-origin isolated capability" is a TODO. Also a preexisting problem; can also probably be merged and fixed later.

  • The sentence "TODO Whenever a Document object is discarded, each WorkletGlobalScope whose owner document is that Document object, should clear its owner document." is not carried over from the Worklets spec. This is a bit trickier:Attempted to fix this with the latest commits; PTAL


After we get this merged, we can tackle some of the easier open issues, ideally with tests. For example, the minor TODOs above, or w3c/css-houdini-drafts#506, or w3c/css-houdini-drafts#985 . Probably also w3c/css-houdini-drafts#505 since at least Chrome appears to be restricting worklets to secure contexts.Fixed this in this PR

Before merging this, I need to canvas the worklet-using specs and make sure they'll keep working, and update their links as appropriate (e.g. changing create a WorkletGlobalScope to create a worklet global scope). That may reveal more <dfn>s to export.


/acknowledgements.html ( diff )
/iana.html ( diff )
/index.html ( diff )
/indices.html ( diff )
/infrastructure.html ( diff )
/named-characters.html ( diff )
/obsolete.html ( diff )
/parsing.html ( diff )
/references.html ( diff )
/rendering.html ( diff )
/syntax.html ( diff )
/webappapis.html ( diff )
/webstorage.html ( diff )
/window-object.html ( diff )
/workers.html ( diff )
/xhtml.html ( diff )
/worklets.html ( diff )

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

Ooh, exciting.

Should we annotate these IDL blocks with SecureContext?

<var>reservedEnvironment</var>'s <span
data-x="concept-environment-target-browsing-context">target browsing context</span>, and <span
data-x="concept-environment-active-service-worker">active service worker</span> to
<var>reservedEnvironment</var>'s <span
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I find this as clear as the previous wording.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. I preferred the way the worklets spec does it, which involves less repetition, so I normalized both to this style.

<ul>
<li><p>Are thread-agnostic. That is, they are not designed to run on a dedicated separate thread,
like each worker is. Implementations can run worklets wherever they choose (including on the main
thread).</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if this holds for audio worklets with shared memory, but I guess it does in theory, but not really in practice.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think they're thread-agnostic, just not process-agnostic.

Copy link
Member

Choose a reason for hiding this comment

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

It's just that you wouldn't have a good time if you ran the audio worklet on the main thread.

source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
@domenic
Copy link
Member Author

domenic commented Oct 13, 2020

Note to self: I'm also hoping to land #4352 soon, so this will need some minor updates there, by incorporating @Ms2ger's work in w3c/css-houdini-drafts#984

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

I found a few potential issues and a couple nits, but largely looks good to me.

@sideshowbarker are there any special considerations with adding an additional file to the multipage version?

<ul>
<li><p>Are thread-agnostic. That is, they are not designed to run on a dedicated separate thread,
like each worker is. Implementations can run worklets wherever they choose (including on the main
thread).</p></li>
Copy link
Member

Choose a reason for hiding this comment

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

It's just that you wouldn't have a good time if you ran the audio worklet on the main thread.

source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved

<dt>The <span data-x="concept-settings-object-cross-origin-isolated-capability">cross-origin
isolated capability</span></dt>
<dd><p>Return <span class="XXX">TODO</span>.</p></dd>
Copy link
Member

Choose a reason for hiding this comment

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

This we can inherit, no? I guess there's again the question as to whether we require COEP to be specified because of imports.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I prefer leaving this as a TODO for now, ideally getting some tests.

source Show resolved Hide resolved
source Show resolved Hide resolved
source Outdated Show resolved Hide resolved
<li>
<p><span>Fetch a worklet script graph</span> given <var>moduleURL</var>,
<var>insideSettings</var>, <var>worklet</var>'s <span>worklet destination type</span>, <span
class="XXX">what credentials mode?</span>, <var>insideSettings</var>, and <var>worklet</var>'s
Copy link
Member

Choose a reason for hiding this comment

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

It's either same-origin or include, right? Any reason not to go with same-origin? Or do we want to write tests before resolving this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I suspect it's whatever was originally used with addModule(). Fixing this seems to require some plumbing to store the credential alongside the URL. (Which leads to complicated questions about what if you addModule() the same module twice with two different credentials...) Maybe related: w3c/css-houdini-drafts#264

Copy link

@padenot padenot left a comment

Choose a reason for hiding this comment

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

A couple comments from an Audio WG point of view, let me know if I can be clearer, audio programming has very strict constraints that are a bit unusual.

<code>WorkletGlobalScope</code> is expected to be shared between multiple separate scripts. (This
is similar to how a single <code>Window</code> is shared between multiple separate scripts.)</p>

<h4 id="worklets-idempotent">Code idempotence</h4>
Copy link

Choose a reason for hiding this comment

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

This section doesn't reflect the reality. The AudioWorklet requires the opposite: a single scope, statefullness, memory sharing via accessing a global, etc.

This is the case for rather fundamental reasons: audio programming is very often stateful (to output an audio sample at time t, we need to know the value of the sample at t-1, and state that was computed prior to compute t), and of course performance: sharing large audio buffers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting. This is ported straight from the worklets spec, but I guess we shouldn't add things that are known-wrong in the porting process.

I guess the simplest way to fix this would be to say "some worklets" instead of "worklets"... I'll try something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess this section already says "Some specifications which use worklets", not all. So I think this section already reflects reality. Do you disagree?

Copy link
Member

Choose a reason for hiding this comment

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

It's probably worth calling out that worklets serve both use cases. Both stateless and stateful, and short and long-running operations.

Copy link

Choose a reason for hiding this comment

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

That would be ideal.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added such a paragraph; PTAL.

data-x="">process</code>" property and convert it into a <code
data-x="idl-Function">Function</code> at registration time, as part of the <code
data-x="dom-FakeWorkletGlobalScope-registerFake">registerFake()</code> method steps.</p>

Copy link

Choose a reason for hiding this comment

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

The Audio WG is exploring this. Classes are nice, but are problematic for WASM integration.

Copy link
Member Author

Choose a reason for hiding this comment

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

To be clear, the idea here is to use classes, but instead of using the style in this toy example which Get()s and converts the method every time, use the architecture that audio worklet and paint worklet use, where you Get() and convert the method at registration time.

@domenic
Copy link
Member Author

domenic commented Oct 14, 2020

I just realized that w3c/css-houdini-drafts#264 is a pretty important bug fix (it fixes the problem described in w3c/css-houdini-drafts#264 (comment)) so I think I should pull that in before we land this.

@sideshowbarker
Copy link
Contributor

@sideshowbarker are there any special considerations with adding an additional file to the multipage version?

None that come to mind. We’re not maintaining a static list of output filenames anywhere — not in any code nor in any support files — so there’s nothing to update as far as that goes. Everything’s just keyed off the split-filename attributes in the source. So I think we’ll just end up with the additional file and everything else just keeps working as it has been.

@sideshowbarker sideshowbarker changed the title Move worklets into to the HTML Standard Move worklets into the HTML Standard Oct 15, 2020
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

I'm happy with this. Lots of details to figure out still, but that's no different from the status quo and this does improve on that, e.g., by having worklets limited to secure contexts.

@sideshowbarker sideshowbarker added the impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation label Dec 2, 2020
@sideshowbarker
Copy link
Contributor

cc @whatwg/documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impacts documentation Used by documentation communities, such as MDN, to track changes that impact documentation topic: worklets
4 participants