Closed Bug 1431353 Opened 7 years ago Closed 7 years ago

Investigate improving performance of off-thread parsing

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla60
Tracking Status
firefox60 --- fixed

People

(Reporter: jonco, Assigned: jonco)

References

Details

Attachments

(2 files)

We have an API to parse JS code in on a helper thread while leaving the main thread free to do other things. I'd like us to make heavier use of this in the future, specifically for preloading module scripts. This bug is about improving its performance.
First of all, we currently only allow a single off-thread parse to be active at once. I'd like to remove this limitation. The comments say: // Don't allow simultaneous off thread parses, to reduce contention on the // atoms table. Note that wasm compilation depends on this to avoid // stalling the helper thread, as off thread parse tasks can trigger and // block on other off thread wasm compilation tasks. (see https://searchfox.org/mozilla-central/source/js/src/vm/HelperThreads.cpp#1194 ) We have a per-zone atom cache that was added fairly recently (bug 1350760) so access to the atoms table should not be such a bottleneck now. Luke, is the point about wasm compilation still valid? What can we do to address this?
Flags: needinfo?(luke)
Good news: this comment goes back to the beginning and it is to prevent a dining philosophers deadlock since parse tasks with asm.js could block on other helper tasks. Since then, we (Lars) made scheduling a hair more sophisticated by adding the "isMaster" argument (which means "this task can block on other helper tasks completing) to checkTaskThreadLimit() which ensures that we never have all helper threads running master tasks. We even set isMaster=true in canStartParseTask() with a comment for asm.js... but apparently we never bumped maxParseTasks() up from 1 :P
Flags: needinfo?(luke)
The master task management was inspired by off-thread parsing but was actually implemented for the sake of wasm tiered compilation, which initially had a master task. (I'm fairly sure Luke later rewrote that code to avoid the master task for wasm.) Feel free to increase the maximum number of parse tasks :) (Insert standard observation about needing a more dynamic scheduler.)
Great, here's a patch to remove this limit.
Attachment #8943966 - Flags: review?(luke)
We should expose this via the shell so that it gets fuzz coverage. Previously we could only compile a single script off-thread at a time. This patch removes this limitation and gives each shell context a list of off-thread parse jobs. Shell functions that start an off-thread job (offThreadCompileScript, offThreadCompileModule and offThreadDecodeScript) now return an integer ID. This can then be passed to the functions that wait for the jobs to finish (runOffThreadScript, finishOffThreadModule and runOffThreadDecodedScript). So as not to have to change all the existing test code I made the ID argument optional in the case where there's only a single pending job.
Attachment #8943967 - Flags: review?(luke)
Great to have this fixed!
Attachment #8943966 - Flags: review?(luke) → review+
Comment on attachment 8943967 [details] [diff] [review] bug1431353-shell-off-thread-jobs Review of attachment 8943967 [details] [diff] [review]: ----------------------------------------------------------------- Nice!
Attachment #8943967 - Flags: review?(luke) → review+
Pushed by jcoppeard@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/91e2856488e7 Remove limit on number of threads used for off-thread parsing r=luke https://hg.mozilla.org/integration/mozilla-inbound/rev/467d285e001c Regoranise the shell interface to off-thread parsing to allow concurrent off-thread parse jobs r=luke
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla60
Depends on: 1433128
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: