New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 591558 link

Starred by 5 users

Issue metadata

Status: Started
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Feature



Sign in to add a comment

Parser inserted scripts and external should Compile and Execute in separate tasks

Project Member Reported by esprehn@chromium.org, Mar 3 2016

Issue description

Looking at traces v8 compilation is often 50% of the runtime for a given script. This is especially true for very large scripts (ex. YouTube). We should break this into two tasks so instead of ScriptController both compiling and executing external scripts all at once, it should compile first, then execute next. We can even do this for parser inserted inline scripts since it's not observable that we yield the parser twice, once after compile and then again after execute. This should improve the responsiveness of the event loop quite a lot during page load.
 
js-compile-tasks.png
58.9 KB View Download
Cc: jochen@chromium.org
Summary: Parser inserted scripts and external should Compile and Execute in separate tasks (was: External scripts should Compile and Execute in separate tasks)
We should really do this for both parser inserted and external scripts. We only need to sync compile inline ones.
Cc: bmeu...@chromium.org verwa...@chromium.org
Components: -Blink>JavaScript Blink>JavaScript>Runtime
Labels: -Type-Bug Type-Feature
Status: Available (was: Untriaged)
Cc: -bmeu...@chromium.org -verwa...@chromium.org vogelheim@chromium.org
Components: -Blink>JavaScript>Runtime Blink>Bindings
Daniel, interested to take a look?
Cc: rmcilroy@chromium.org
Components: Blink>Scheduling
Any luck here? :)

Comment 6 by jochen@chromium.org, Apr 27 2016

the "v8.compile" and "v8.run" events already correspond to two different methods on V8ScriptRunner. It would just require calling them in two tasks instead of one.

We could even split the parsing and compiling, and do the parsing on the v8 parser background thread.

I currently don't have free cycles to look at this myself, sorry

Comment 7 by adamk@chromium.org, May 25 2016

Cc: seththompson@chromium.org
Heard from haraken that vogelheim might be working on this. Daniel, is that the case?
#7: No, am not working on this.

(As jochen says, most of this should be doable with current APIs. Making compile fully concurrent, as I think #2 suggests, would require significant effort.)
Yes, I think this is doable with current APIs. Also we just need to split the two tasks, don't need to make compile fully concurrent.

Can we find someone in the V8 team to work on this?

I was not suggesting any type of concurrent compile in #2, what I'm saying is that for a parser inserted script like:

<script>....</script>

we can execute this by doing:

1. postTask() a CompileScript task.
2. postTask() an ExecuteScript task once (1) is done.

we can do the same thing for:

<script src="thing.js"></script>

where when the bytes come back from the network we do the same two post tasks.

I know we use the ScriptStreamer thread sometimes for this too, this would be an alternative path.

The only case we need to run both steps at the same time is if you do:

script = document.createElement("script")
script.textContent = "...";
appendChild(script)

since that expects a synchronous execution of the script tag inside appendChild.

Btw, why don't we use the ScriptStreamer thread for parser inserted scripts today? We could just postTask() the bytes to the background thread... (I know the background thread is not always a win, just curious why we didn't do that.)
@haraken, no we don't currently have anybody available to work on this.
Cc: hablich@chromium.org
Cc: kinuko@chromium.org
Cc: marja@chromium.org
I'm interested in this!

Comment 15 by marja@chromium.org, Jul 12 2016

Owner: marja@chromium.org
Owner: haraken@chromium.org
haraken@ Do you think we could tackle this in Q1? It would help quite a bit to avoid nested iframes inserting large scripts causing jank in the main frame with long compiles, ex. AMP.
Cc: -vogelheim@chromium.org
Owner: marja@chromium.org
I think marja@ has been working on this.

marja@: What's the current status?

Cc: -kinuko@chromium.org
Owner: jochen@chromium.org
jochen@: Is it likely that someone in your team can work on this?

Cc: esprehn@chromium.org
Cc: kenjibaheux@chromium.org
Owner: esprehn@chromium.org
Elliott, you said you had somebody that might be able to look into this?
Owner: jbroman@chromium.org
jbroman@ Said he might be interested.

I think what needs to change here is changing the code in HTMLScriptRunner::executeParsingBlockingScripts to first call compile() on each script, then execute() and always yield after each compile or execute step.
Status: Started (was: Available)
Project Member

Comment 26 by bugdroid1@chromium.org, Apr 25 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/e0e2dc3f7bd8b62483c2c4b8f1739158a1b05c79

commit e0e2dc3f7bd8b62483c2c4b8f1739158a1b05c79
Author: jbroman <jbroman@chromium.org>
Date: Tue Apr 25 20:52:54 2017

PendingScript: Unify watching_for_load_ with client_.

A client is "watching for load" iff it is the client of the PendingScript.
These variables are trivially redundant, and so it's simpler to just hold one.

BUG=591558

Review-Url: https://codereview.chromium.org/2840663004
Cr-Commit-Position: refs/heads/master@{#467105}

[modify] https://crrev.com/e0e2dc3f7bd8b62483c2c4b8f1739158a1b05c79/third_party/WebKit/Source/core/dom/PendingScript.cpp
[modify] https://crrev.com/e0e2dc3f7bd8b62483c2c4b8f1739158a1b05c79/third_party/WebKit/Source/core/dom/PendingScript.h

Project Member

Comment 27 by bugdroid1@chromium.org, May 2 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/ce9f0aa85bc1e34ad03dc963ef589dc3fbed21bd

commit ce9f0aa85bc1e34ad03dc963ef589dc3fbed21bd
Author: jbroman <jbroman@chromium.org>
Date: Tue May 02 16:35:29 2017

Explicitly track the lifecycle of PendingScript.

This moves the lifecycle tracking of PendingScript from relying
on querying its parts (the resource, streamer, etc.) to maintaining
an explicit state machine.

Firstly, this means that the apparent state to change is timed to
coincide with when clients are notified (as opposed to a client being
able to notice that a PendingScript is finished before being notified).

It also paves the way for additional steps (e.g. separately scheduled
compile of the script) without making IsReady and ErrorOccurred yet
more complicated.

BUG=591558

Review-Url: https://codereview.chromium.org/2828193003
Cr-Commit-Position: refs/heads/master@{#468676}

[modify] https://crrev.com/ce9f0aa85bc1e34ad03dc963ef589dc3fbed21bd/third_party/WebKit/Source/core/dom/ClassicPendingScript.cpp
[modify] https://crrev.com/ce9f0aa85bc1e34ad03dc963ef589dc3fbed21bd/third_party/WebKit/Source/core/dom/ClassicPendingScript.h

Sign in to add a comment