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

[LoAF] Should be a way to switch script "Entry Point" without yielding. #2

Open
mmocny opened this issue Nov 7, 2023 · 2 comments
Open

Comments

@mmocny
Copy link

mmocny commented Nov 7, 2023

This is related to #3, but enough different that I wanted to fork.

Rather than asking for arbitrary annotations, I think it would be worthwhile to just have a mechanism for explicitly switching script "entry points" -- and let LoAF work as normal beyond that -- but without needing to turn to macrotask scheduling.

For example, perhaps queueMicrotask could be seen as an explicit scheduling call, and could have a distinct Entry Point. That is just a strawman idea.


I just tried a few experiments locally. At a high level, what we would like is for a script to be able to move some continuation into a new "loaf entrypoint", such that loaf can "switch script attribution" to it.

The easiest working example is to just setTimeout(callback, 0) or scheduler.postTask(callback) (provided that callback was actually created by the script you want to change attribution to). But this requires a macrotask hop with FIFO scheduling, which may not be desirable.

I also tried to use scheduler.yield() which has LIFO scheduling, but it did not work as expected:

scheduler.yield().then(callback);

I would have expected that to be a "resolve-promise" entrypoint. I wonder if this is just a bug in LoAF, or expected? (also, while the sourceLocation didn't change scripts, the character offset is 0, so something is funky)

I also tried to find some hacky existing mechanism to switch entry points but stay within the same macrotask. I tried to create EventTarget or <button> and then use addEventListener + dispatchEvent, or various Observers etc, but none of those worked.

@mmocny
Copy link
Author

mmocny commented Nov 10, 2023

Idea: Perhaps just changing LoAF to treat EventTarget listeners as unique entry-point would be the perfect interface for this use case?

Instead of a library managing its own callback queue and then somehow scheduling those callbacks-- thats already what EventTarget and dispatchEvent does, and there is existing precedent with normal page events already splitting up script attribution on event listener calls.

LoAF script "type" and "name" attribution would also be a lot more useful that way, not just solving the "sourceLocation" problem.

And EventTarget dispatches listeners synchronously, which addresses the concern with just using yield/postTask. If you explicitly want to be asynchronous, you can use explicit scheduling.

@noamr
Copy link
Collaborator

noamr commented Nov 16, 2023

As we spoke in a private chat, this wouldn't work in terms of microtask checkpoints. a "real" entry point would call those custom entry points which would add tasks to the microtask queue, and that queue would then be filled with microtasks from different sources without a way to measure them separately. I think #3 is a more doable approach.

@caribouW3 caribouW3 transferred this issue from w3c/longtasks Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants