Skip to content

Commit

Permalink
Editorial: decrease traversals for module graph fetching
Browse files Browse the repository at this point in the history
Previously, we could invoke the internal module script graph fetching
procedure once for each combination of node and ancestor list, i.e. once
for each node and for each path to the node. This could be up to O(2^n)
for n nodes, as seen in
https://gist.github.com/domenic/d877f8b2e6d6ae62a9c94f916739e4db.

This change simplifies the model by using a single visited set per
top-level fetch, which ensures that the internal module script graph
fetching procedure is only invoked once for each node.

This change is technically editorial, as it has no visible, testable
effects. (It may subtly change the choice of error reported, but that
was already nondeterministic, and being fixed in whatwg#2991.) It's intended
to make it much easier for implementers to follow the standard as
written without causing themselves massive slowdowns.
  • Loading branch information
domenic authored and Alice Boxhall committed Jan 7, 2019
1 parent c8a9a5f commit b6eabf4
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -86772,10 +86772,12 @@ interface <dfn>NavigatorOnLine</dfn> {
script</span> (on success).</p>

<ol>
<li><p>Let <var>visited set</var> be « <var>url</var> ».</p></li>

<li><p>Perform the <span>internal module script graph fetching procedure</span> given
<var>url</var>, <var>settings object</var>, <var>destination</var>, <var>cryptographic
nonce</var>, <var>parser state</var>, <var>credentials mode</var>, <var>settings object</var>, a
new empty list, "<code data-x="">client</code>", and with the <var>top-level module fetch
nonce</var>, <var>parser state</var>, <var>credentials mode</var>, <var>settings object</var>,
<var>visited set</var>, "<code data-x="">client</code>", and with the <var>top-level module fetch
flag</var> set. If the caller of this algorithm specified custom <span
data-x="fetching-scripts-perform-fetch">perform the fetch</span> steps, pass those along as
well.</p>
Expand All @@ -86792,10 +86794,12 @@ interface <dfn>NavigatorOnLine</dfn> {
failure) or a <span>module script</span> (on success).</p>

<ol>
<li><p>Let <var>visited set</var> be « <var>url</var> ».</p></li>

<li><p>Perform the <span>internal module script graph fetching procedure</span> given
<var>url</var>, <var>fetch client settings object</var>, <var>destination</var>, the empty
string, "<code data-x="">not parser-inserted</code>", <var>credentials mode</var>, <var>module
map settings object</var>, a new empty list, "<code data-x="">client</code>", and with the
map settings object</var>, <var>visited set</var>, "<code data-x="">client</code>", and with the
<var>top-level module fetch flag</var> set. If the caller of this algorithm specified custom
<span data-x="fetching-scripts-perform-fetch">perform the fetch</span> steps, pass those along as
well.</p>
Expand All @@ -86814,11 +86818,14 @@ interface <dfn>NavigatorOnLine</dfn> {
<p>To perform the <dfn>internal module script graph fetching procedure</dfn> given a
<var>url</var>, a <var>fetch client settings object</var>, a <var>destination</var>, a
<var>cryptographic nonce</var>, a <var>parser state</var>, a <var>credentials mode</var>, a
<var>module map settings object</var>, an <var>ancestor list</var>, a <var>referrer</var>, and a
<var>module map settings object</var>, a <var>visited set</var>, a <var>referrer</var>, and a
<var>top-level module fetch</var> flag, perform these steps. The algorithm will asynchronously
complete with either null (on failure) or a <span>module script</span> (on success).</p>

<ol>
<li><p>Assert: <var>visited set</var> <span data-x="list contains">contains</span>
<var>url</var>.</p></li>

<li><p><span>Fetch a single module script</span> given <var>url</var>, <var>fetch client settings
object</var>, <var>destination</var>, <var>cryptographic nonce</var>, <var>parser state</var>,
<var>credentials mode</var>, <var>module map settings object</var>, <var>referrer</var>, and the
Expand All @@ -86839,8 +86846,7 @@ interface <dfn>NavigatorOnLine</dfn> {

<li><p>If the <var>top-level module fetch</var> flag is set, <span data-x="fetch the descendants
of and instantiate a module script">fetch the descendants of and instantiate</span>
<var>result</var> given <var>destination</var> and an ancestor list obtained by <span
data-x="list append">appending</span> <var>url</var> to <var>ancestor list</var>. Otherwise,
<var>result</var> given <var>destination</var> and <var>visited set</var>. Otherwise,
<span data-x="fetch the descendants of a module script">fetch the descendants of</span>
<var>result</var> given the same arguments.</p></li>

Expand Down Expand Up @@ -86943,13 +86949,11 @@ interface <dfn>NavigatorOnLine</dfn> {
</ol>

<p>To <dfn>fetch the descendants of a module script</dfn> <var>module script</var>, given a
<var>destination</var> and an optional <var>ancestor list</var>, run these steps. The algorithm
will asynchronously complete with either null (on failure) or with <var>module script</var> (on
<var>destination</var> and a <var>visited set</var>, run these steps. The algorithm will
asynchronously complete with either null (on failure) or with <var>module script</var> (on
success).</p>

<ol>
<li><p>If <var>ancestor list</var> was not given, let it be an empty <span>list</span>.</p></li>

<li><p>If <var>module script</var> <span data-x="concept-module-script-is-errored">is
errored</span> or <span data-x="concept-module-script-has-instantiated">has instantiated</span>,
asynchronously complete this algorithm with <var>module script</var>, and abort these
Expand All @@ -86976,9 +86980,17 @@ interface <dfn>NavigatorOnLine</dfn> {
href="#validate-requested-module-specifiers">previously successful</a> with these same two
arguments.</p></li>

<li><p>If <var>ancestor list</var> does not <span data-x="list contains">contain</span>
<var>url</var>, <span data-x="list append">append</span> <var>url</var> to
<var>urls</var>.</p></li>
<li>
<p>If <var>visited set</var> does not <span data-x="list contains">contain</span>
<var>url</var>, then:</p>

<ol>
<li><p><span data-x="list append">Append</span> <var>url</var> to <var>urls</var>.</p></li>

<li><p><span data-x="set append">Append</span> <var>url</var> to <var>visited
set</var>.</p></li>
</ol>
</li>
</ol>
</li>

Expand All @@ -86989,7 +87001,7 @@ interface <dfn>NavigatorOnLine</dfn> {
<var>module script</var>'s <span data-x="concept-module-script-nonce">cryptographic
nonce</span>, <var>module script</var>'s <span data-x="concept-module-script-parser">parser
state</span>, <var>destination</var>, <var>module script</var>'s <span>settings object</span>,
<var>module script</var>'s <span>settings object</span>, <var>ancestor list</var>, <var>module
<var>module script</var>'s <span>settings object</span>, <var>visited set</var>, <var>module
script</var>'s <span data-x="concept-module-script-base-url">base URL</span>, and with the
<var>top-level module fetch</var> flag unset. If the caller of this algorithm specified custom
<span data-x="fetching-scripts-perform-fetch">perform the fetch</span> steps, pass those along
Expand Down Expand Up @@ -87035,13 +87047,15 @@ interface <dfn>NavigatorOnLine</dfn> {
</ol>

<p>To <dfn>fetch the descendants of and instantiate a module script</dfn> <var>module
script</var>, given a <var>destination</var> and an optional <var>ancestor list</var>, run these
script</var>, given a <var>destination</var> and an optional <var>visited set</var>, run these
steps. The algorithm will asynchronously complete with either null (on failure) or with
<var>module script</var> (on success).</p>

<ol>
<li><p>If <var>visited set</var> was not given, let it be an empty <span>set</span>.</p></li>

<li><p><span data-x="fetch the descendants of a module script">Fetch the descendants of</span>
<var>module script</var>, given <var>destination</var> and <var>ancestor list</var>.</p></li>
<var>module script</var>, given <var>destination</var> and <var>visited set</var>.</p></li>

<li><p>Return from this algorithm, and run the following steps when <span data-x="fetch the
descendants of a module script">fetching the descendants of a module script</span> asynchronously
Expand Down Expand Up @@ -120578,6 +120592,7 @@ INSERT INTERFACES HERE
Henry Mason,
Henry Story,
Hermann Donfack Zeufack,
Hiroshige Hayashizaki,
Hugh Bellamy,
Hugh Guiney,
Hugh Winkler,
Expand Down

0 comments on commit b6eabf4

Please sign in to comment.