From 0465cfc6e0b652006659e45bf5ddc2f505b0b6c5 Mon Sep 17 00:00:00 2001 From: Ross McIlroy Date: Wed, 30 Oct 2019 12:10:00 +0000 Subject: [PATCH 1/2] Associcate idle callback lists and idle periods with the event loop. The idle callback lists and idle periods should be per-event loop rather than per-window. This change moves the lists and the starting of idle periods to be on a per-event loop basis. Addresses #82 --- index.html | 79 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 32 deletions(-) diff --git a/index.html b/index.html index b0060bf..152c172 100644 --- a/index.html +++ b/index.html @@ -341,19 +341,24 @@

Window interface extensions

Each Window has:

+ +

In addition, each event loop has:

+ +

The requestIdleCallback method

@@ -367,8 +372,11 @@

The requestIdleCallback by one.
  • Let handle be the current value of window's idle callback identifier.
  • -
  • Push callback to the end of window's list - of idle request callbacks, associated with handle.
  • +
  • Let event_loop be the event loop associated with + window
  • +
  • Push callback to the end of event_loop's + list of idle request callbacks, associated with handle + and window.
  • Return handle and then continue running this algorithm asynchronously.

    The following steps run in parallel and queue a timer @@ -421,11 +429,13 @@

    The cancelIdleCallback

    1. Let window be this Window object.
    2. -
    3. Find the entry in either the window's list of idle +
    4. Let event_loop be the event loop associated with + window
    5. +
    6. Find the entry in either the event_loop's list of idle request callbacks or list of runnable idle callbacks that is - associated with the value handle. + associated with the value handle and window.
    7. -
    8. If there is such an entry, remove it from both window's +
    9. If there is such an entry, remove it from both event_loop's list of idle request callbacks and the list of runnable idle callbacks.
    10. @@ -479,7 +489,7 @@

      Start an idle period algorithm

      the event loop is otherwise idle:

      1. Let last_deadline be the last idle period deadline - associated with window + associated with event_loop
      2. If last_deadline is greater than the current time, return from this algorithm.
      3. Optionally, if the user agent determines the idle period should @@ -509,11 +519,11 @@

        Start an idle period algorithm

        responsiveness to new user input within the threshold of human perception.

      4. -
      5. Let pending_list be window's list of idle - request callbacks. +
      6. Let pending_list be event_loop's list of + idle request callbacks.
      7. -
      8. Let run_list be window's list of runnable - idle callbacks. +
      9. Let run_list be event_loop's list of + runnable idle callbacks.
      10. Append all entries from pending_list into run_list preserving order.
      11. @@ -521,19 +531,20 @@

        Start an idle period algorithm

      12. Queue a task on the queue associated with the idle-task task source, which performs the steps defined in the invoke idle callbacks algorithm with deadline and - window as parameters. + event_loop as parameters.
      13. Save deadline as the last idle period deadline - associated with window.
      14. + associated with event_loop.

      The task source for these tasks is the idle-task task source.

      The time between now and deadline is referred to as the idle period. There can only be one idle period - active at a given time for any given window. The idle period can end - early if the user agent determines that it is no longer idle. If so, - the next idle period cannot start until after deadline.

      + active at a given time for any given event loop. The idle period + can end early if the user agent determines that it is no longer idle. If + so, the next idle period cannot start until after deadline. +

  • @@ -544,9 +555,10 @@

    Invoke idle callbacks algorithm

    to newly scheduled high-priority work, return from the algorithm.
  • Let now be the current time.
  • If now is less than deadline and the - window's list of runnable idle callbacks is not empty: + event_loop's list of runnable idle callbacks is not + empty:
      -
    1. Pop the top callback from window's +
    2. Pop the top callback from event_loop's list of runnable idle callbacks.
    3. Let deadlineArg be a new IdleDeadline. Set the time associated with deadlineArg to @@ -555,10 +567,10 @@

      Invoke idle callbacks algorithm

    4. Call callback with deadlineArg as its argument. If an uncaught runtime script error occurs, then report the error.
    5. -
    6. If window's list of runnable idle callbacks +
    7. If event_loop's list of runnable idle callbacks is not empty, queue a task which performs the steps in the invoke idle callbacks algorithm with deadline - and window as a parameters and return from this + and event_loop as a parameters and return from this algorithm
  • @@ -572,16 +584,19 @@

    Invoke idle callbacks algorithm

    Invoke idle callback timeout algorithm

    The invoke idle callback timeout algorithm:

      +
    1. Let event_loop be the event loop associated with + window argument passed to the algorithm
    2. Let callback be the result of finding the entry in - window's list of idle request callbacks or the list + event_loop's list of idle request callbacks or the list of runnable idle callbacks that is associated with the value - given by the handle argument passed to the algorithm. + given by the handle and window arguments passed + to the algorithm.
    3. If callback is not undefined:
        -
      1. Remove callback from both window's list - of idle request callbacks and the list of runnable idle - callbacks.
      2. +
      3. Remove callback from both event_loop's + list of idle request callbacks and the list of runnable + idle callbacks.
      4. Let now be the current time.
      5. Let deadlineArg be a new IdleDeadline. Set the time associated with deadlineArg to From 426afac7b40a1e0d6c60a97a17ecdb56954b8368 Mon Sep 17 00:00:00 2001 From: Ross McIlroy Date: Wed, 30 Oct 2019 17:18:01 +0000 Subject: [PATCH 2/2] Replace event loop with similar-origin window agent --- index.html | 63 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/index.html b/index.html index 152c172..ccd0f24 100644 --- a/index.html +++ b/index.html @@ -83,7 +83,8 @@

        Dependencies

        The terms browsing context - , event loop, + , similar-origin + window agent, event loop, event loop processing model, spin the event loop, fully active, @@ -345,16 +346,17 @@

        Window interface extensions

        initially be zero.
      6. -

        In addition, each event loop has:

        +

        In addition, each similar-origin window agent has:

        • A list of idle request callbacks. The list MUST be initially empty and each entry in this list is identified by Window and a number, the combination of which MUST be unique within the list for - the lifetime of the event loop.
        • + the lifetime of the similar-origin window agent.
        • A list of runnable idle callbacks. The list MUST be initially empty and each entry in this list is identified by a Window and a number, the combination of which which MUST be unique - within the list for the lifetime of the event loop.
        • + within the list for the lifetime of the similar-origin window agent. +
        • A last idle period deadline, which is a DOMHighResTimeStamp which MUST initially be zero.
        @@ -372,9 +374,9 @@

        The requestIdleCallback by one.
      7. Let handle be the current value of window's idle callback identifier.
      8. -
      9. Let event_loop be the event loop associated with - window
      10. -
      11. Push callback to the end of event_loop's +
      12. Let agent be the similar-origin window agent + associated with window
      13. +
      14. Push callback to the end of agent's list of idle request callbacks, associated with handle and window.
      15. Return handle and then continue running this algorithm @@ -429,13 +431,13 @@

        The cancelIdleCallback

        1. Let window be this Window object.
        2. -
        3. Let event_loop be the event loop associated with - window
        4. -
        5. Find the entry in either the event_loop's list of idle +
        6. Let agent be the similar-origin window agent + associated with window
        7. +
        8. Find the entry in either the agent's list of idle request callbacks or list of runnable idle callbacks that is associated with the value handle and window.
        9. -
        10. If there is such an entry, remove it from both event_loop's +
        11. If there is such an entry, remove it from both agent's list of idle request callbacks and the list of runnable idle callbacks.
        12. @@ -485,11 +487,12 @@

          Processing

          Start an idle period algorithm

          The start an idle period algorithm, which is called - by the event loop processing model when it determines that - the event loop is otherwise idle:

          + by the event loop processing model, when it determines that + the event loop is otherwise idle, passing a similar-origin + window agent as the argument agent:

          1. Let last_deadline be the last idle period deadline - associated with event_loop + associated with agent
          2. If last_deadline is greater than the current time, return from this algorithm.
          3. Optionally, if the user agent determines the idle period should @@ -519,10 +522,10 @@

            Start an idle period algorithm

            responsiveness to new user input within the threshold of human perception.

          4. -
          5. Let pending_list be event_loop's list of +
          6. Let pending_list be agent's list of idle request callbacks.
          7. -
          8. Let run_list be event_loop's list of +
          9. Let run_list be agent's list of runnable idle callbacks.
          10. Append all entries from pending_list into @@ -531,20 +534,20 @@

            Start an idle period algorithm

          11. Queue a task on the queue associated with the idle-task task source, which performs the steps defined in the invoke idle callbacks algorithm with deadline and - event_loop as parameters. + agent as parameters.
          12. Save deadline as the last idle period deadline - associated with event_loop.
          13. + associated with agent.

          The task source for these tasks is the idle-task task source.

          The time between now and deadline is referred to as the idle period. There can only be one idle period - active at a given time for any given event loop. The idle period - can end early if the user agent determines that it is no longer idle. If - so, the next idle period cannot start until after deadline. -

          + active at a given time for any given similar-origin window agent. + The idle period can end early if the user agent determines that it is no + longer idle. If so, the next idle period cannot start until after + deadline.

          @@ -555,10 +558,10 @@

          Invoke idle callbacks algorithm

          to newly scheduled high-priority work, return from the algorithm.
        13. Let now be the current time.
        14. If now is less than deadline and the - event_loop's list of runnable idle callbacks is not + agent's list of runnable idle callbacks is not empty:
            -
          1. Pop the top callback from event_loop's +
          2. Pop the top callback from agent's list of runnable idle callbacks.
          3. Let deadlineArg be a new IdleDeadline. Set the time associated with deadlineArg to @@ -567,10 +570,10 @@

            Invoke idle callbacks algorithm

          4. Call callback with deadlineArg as its argument. If an uncaught runtime script error occurs, then report the error.
          5. -
          6. If event_loop's list of runnable idle callbacks +
          7. If agent's list of runnable idle callbacks is not empty, queue a task which performs the steps in the invoke idle callbacks algorithm with deadline - and event_loop as a parameters and return from this + and agent as a parameters and return from this algorithm
        15. @@ -584,17 +587,17 @@

          Invoke idle callbacks algorithm

          Invoke idle callback timeout algorithm

          The invoke idle callback timeout algorithm:

            -
          1. Let event_loop be the event loop associated with - window argument passed to the algorithm
          2. +
          3. Let agent be the similar-origin window agent + associated with window argument passed to the algorithm
          4. Let callback be the result of finding the entry in - event_loop's list of idle request callbacks or the list + agent's list of idle request callbacks or the list of runnable idle callbacks that is associated with the value given by the handle and window arguments passed to the algorithm.
          5. If callback is not undefined:
              -
            1. Remove callback from both event_loop's +
            2. Remove callback from both agent's list of idle request callbacks and the list of runnable idle callbacks.
            3. Let now be the current time.