-
Notifications
You must be signed in to change notification settings - Fork 18
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
Run to completion violation #12
Comments
Thanks, great point. "any data observed within the function will stay constant as long as that function is active." If we don't implement this, I anticipate once off thread input is supported, folks will build this themselves this via off thread input and SAB. I suspect the cat is, in fact, out of the bag on this one. |
Yeah, how things like performance.now() or Date.now() fit with run to completion is an interesting question as well. I feel like I had a satisfactory answer once upon a time, but no longer remember it. I could indeed see an argument that this is similar to those. |
FWIW, I think it's quite bad to add new high-level APIs that violate this. That will make things much harder to reason about. |
This doesn't seem like what the TAG text is actually referencing, although it is imprecise enough that I could be interpreted in different ways. Regardless we should probably get the text to be more precisely written. Specifically, this sentence is could use refining: "any data observed within the function will stay constant as long as that function is active." In my head, the key constraint of run to completion is about avoiding races in JS state. Just having isInputPending return different values when called within a single function call doesn't seem to me like it violates run to completion. An example of where run to completion is critical: |
The API |
Another example: the From the spec: "The value of complete can thus change while a script is executing." |
That's not really true; see whatwg/html#1055 |
Two things about recentish comments:
|
Thanks Anne, I don't think examples are central to this discussion, though I do find them interesting. Ojan's comment here does a better job of getting to the core of the issue. |
I think the key problem with the API is that the return value of |
@annevk it would help me have a more concrete debate about the trade-offs if you could give examples of specific cases where you are worried non-determinism from this API will cause unexpected or problematic behavior for web authors. For example, I gave sample code above of a case that I think is important not to break (although, last I checked, Gecko does violate even that in some edge cases). Historical precedent may matter here if web authors don't seem to currently have problems with those APIs. That provides some evidence that that definition of run-to-completion might be more strict than is necessary. |
@ojanvafai Just food for thought, but isFramePending has very much the same issue. |
E.g., I'm not sure |
For what it's worth (as I've mentioned in w3ctag/design-reviews#415 (comment)) I tend to think that the run-to-completion principle may be the sort of principle where accidental/hidden violations are more problematic than obvious ones. In other words, some random DOM API that violates run-to-completion because some boolean gets flipped from a different thread seems worse than things like (This is similar to the line of thought that made me more OK with the GC observability aspects of That said, in both cases it's still possible for the violations of these principles to lead to bugs in sites, but it seems more defensible in this sort of case. |
Closing based on @dbaron's comments. |
This API appears to violate https://w3ctag.github.io/design-principles/#js-rtc. It appears to do so fairly fundamentally, as part of its very purpose. In particular, it betrays the presence of input handling code that runs separately from the JavaScript thread, and that thread communicates its state in a way that is not the usual queue-a-task manner.
I'm not sure what to do here, but I think it's a pretty big architectural issue worth highlighting.
Also note that apart from the guidelines, this may violate some ECMAScript spec requirements; I'm not sure, as I think that would either be in the agents part of the spec (too complicated for me) or the jobs part of the spec (broken). /cc @littledan as he has been looking in to some event loop run-to-completion semantics. Also /cc @annevk, since he has been working on some related stuff around "spin the event loop", which per the way its spec is written violates run to completion. (But, from what we can tell, does so in a way that isn't observable via author code.)
I suppose now that the shared memory cat is out of the bag using SharedArrayBuffer, run to completion isn't what it used to be, and maybe this is just a second way to observe changes in other threads. In that case we should probably have the W3C TAG update their design principles.
/cc @slightlyoff @cwilso who were involved in the great WebAudio run-to-completion violation debate of years gone by.
The text was updated successfully, but these errors were encountered: