Skip to content

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

Open

Description

@mmocny

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.

Activity

  1. mmocny commented on Nov 10, 2023

    @mmocny
    ContributorAuthor

    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.

  2. noamr commented on Nov 16, 2023

    @noamr
    Collaborator

    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.

  3. transferred this issue fromw3c/longtaskson Mar 11, 2024
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions