Closed Bug 1734098 Opened 4 years ago Closed 4 years ago

Move instantiation step out of off-thread compile/decode API

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
97 Branch
Tracking Status
firefox97 --- fixed

People

(Reporter: arai, Assigned: arai)

References

(Blocks 1 open bug)

Details

Attachments

(16 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

Currently single-script off-thread API returns JSScript as the result of the task,
either by performing the instantiation off-thread/on-main-thread.

Once off-thread instantiation is removed by bug 1687973, we should be able to make the API fully based on stencil, and let the consumer instantiate as a separate step.

Things to do:

  • Rewrite JS::CompileOffThread consumer to use JS::CompileToStencilOffThread
  • Add JS::InstantiateGlobalStencilAndStartIncrementalEncoding API and rewriteJS::FinishOffThreadScriptAndStartIncrementalEncoding` consumer to use it
  • Remove JS::CompileOffThread and related APIs
  • Add Stencil variant of JS::CompileOffThreadModule and rewrite consumers
  • Remove JS::CompileOffThreadModule and related APIs
  • Add Stencil variant of JS::DecodeOffThreadScript and rewrite consumers
  • Remove JS::DecodeOffThreadScript and related APIs
  • Cleanup ParseTask methods/properties, by removing instantiation-specific part

There's a problem around *StartIncrementalEncoding with CompilationStencil vs ExtensibleCompilationStencil.
currently, ScriptParseTask uses ExtensibleCompilationStencil for instantiation and incremental encoding, and there's no not-borrowing CompilationStencil.

current public API doesn't have a concept of "extensible or not" and ExtensibleCompilationStencil is not exposed.

that means, if we return stencil to the caller before starting incremental encoding,
CompilationStencil::steal is called when returning stencil from JS::FinishOffThreadCompileToStencil, and
then ExtensibleCompilationStencil::steal is called when starting incremental encoding, that performs 2 extra copies.

in term of performance, we'd better exposing ExtensibleCompilationStencil to public API as well, to reduce the possible copy,
but for simplicify, it's better having single type for stencil.

Possible Options:

  • expose ExtensibleCompilationStencil in public API, and add "extensible" variable for some APIs, and add JS::StartIncrementalEncoding API
  • for "finish-off-thread-compilation + instantiate + start-incremental-encoding", keep using single compound API, given it's special case, but refactor the backend, by receiving JS::InstantiateOptions instead carrying it from ParseTask

maybe we can take the latter option, and revisit the design when we hit another instance that requires ExtensibleCompilationStencil in public API

converting JS::FinishOffThreadScript to JS::FinishOffThreadCompileToStencil with JS::InstantiateGlobalStencil also requires 1 extra copy

Depends on: 1743357

bug 1743357 will help the API design by avoid unnecessary copy

with bug 1743357 fixed, we can return ExtensibleCompilationStencil without copy, by storing it in CompilationStencil.ownedBorrowStencil.

There's another problem.
in the current JSScript-based off-thread API, we're performing frontend::PrepareForInstantiate off-main thread.
If we simply decouple the instantiation from the off-thread API, frontend::PrepareForInstantiate cannot be performed,
and the CompilationGCOutput allocation is moved to the main thread.

If we're to move the body of the off-thread task to the embedding side, the preparation step should also be exposed.
so, in either case, we need a public struct that wraps CompilationGCOutput, or the buffer that can be stolen by CompilationGCOutput vectors.

Depends on: 1744176
Depends on: 1744178

Make the stencil-based off-thread API names follow the convention:

  • ...OffThread
  • Finish...OffThread
  • Cancel...OffThread

This patch stack adds more functions for module/decode, with the above naming
convention.

Depends on D133041

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED

This is to support incremental encoding with stencil-based off-thread API.

Depends on D133042

Now there's no code that uses laziness during instantiation, remove the
remaining check for the options

Depends on D133044

Rewrite tests to use stencil-based testing functions:

  • offThreadCompileScript => offThreadCompileToStencil
  • runOffThreadScript => finishOffThreadCompileToStencil+evalStencil

Depends on D133045

  • offThreadCompileModule => offThreadCompileModuleToStencil
  • finishOffThreadModule => finishOffThreadCompileModuleToStencil+instantiateModuleStencil

Depends on D133048

Also make JS::CanDecodeOffThread to receive JS::DecodeOptions.

Depends on D133051

  • offThreadDecodeScript => offThreadDecodeStencil
  • runOffThreadDecodedScript => finishOffThreadDecodeStencil+evalStencil

Depends on D133052

  • DecodeMultiOffThreadStencils => DecodeMultiStencilsOffThread
    • FinishMultiOffThreadStencilDecoder => FinishDecodeMultiStencilsOffThread
    • CancelMultiOffThreadScriptsDecoder => CancelDecodeMultiStencilsOffThread

Also make JS::DecodeMultiStencilsOffThread to receive JS::DecodeOptions,
and make ScriptPreloader to call JS::CanDecodeOffThread.

Depends on D133055

Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/48aa5ca15135 Part 1: Use consistent function name for off-thread stencil API. r=nbp https://hg.mozilla.org/integration/autoland/rev/532328aedaaa Part 2: Add JS::StartIncrementalEncoding. r=nbp https://hg.mozilla.org/integration/autoland/rev/c3b9c8221059 Part 3: Use JS::CompileToStencilOffThread instead of JS::CompileOffThread in ScriptLoader. r=nbp https://hg.mozilla.org/integration/autoland/rev/cfb19671fd4e Part 4: Remove stencil option mismatch check in testing function. r=nbp https://hg.mozilla.org/integration/autoland/rev/3174f1ecfd03 Part 5: Remove shell offThreadCompileScript. r=nbp https://hg.mozilla.org/integration/autoland/rev/ffd72fa3fc59 Part 6: Remove JS::CompileOffThread. r=nbp https://hg.mozilla.org/integration/autoland/rev/0d07931e6bc8 Part 7: Add JS::CompileModuleToStencilOffThread. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/a85846f79eb5 Part 8: Replace shell offThreadCompileModule with offThreadCompileModuleToStencil. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/cf458ad5345a Part 9: Remove JS::CompileOffThreadModule. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/323af9d3e0e1 Part 10: Fix storageType for decoded stencil without borrowBuffer. r=nbp https://hg.mozilla.org/integration/autoland/rev/da83b4571cf2 Part 11: Add JS::DecodeStencilOffThread. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/630055366dac Part 12: Replace shell offThreadDecodeScript with offThreadDecodeStencil. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/7b7c59fc644b Part 13: Remove JS::DecodeOffThreadScript. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/02d7ca7fc45c Part 14: Remove JSScript-related methods from ParseTask. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/cfdf7ed9a5a2 Part 15: Use consistent name for decode multi stencils API. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/08070838c7d2 Part 16: Use CompilationStencil in helper threads. r=tcampbell

Backed out (bug 1744178, bug 1734098) for causing leaks.

Affected platform Linux 18.04 x64 WebRender asan opt

Push with failures

Failure log for wd leaks
Failure log for bc leaks
Other jobs have the same failure log as bc leaks.

Backout link

Also this V-swr bustages, failure log: https://treeherder.mozilla.org/logviewer?job_id=360715600&repo=autoland&lineNumber=71123
and
this py3 mch failures, failure log: https://treeherder.mozilla.org/logviewer?job_id=360720852&repo=autoland&lineNumber=181

Flags: needinfo?(arai.unmht)
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/ce44063a7b80 Part 1: Use consistent function name for off-thread stencil API. r=nbp https://hg.mozilla.org/integration/autoland/rev/03f97dcd2bc2 Part 2: Add JS::StartIncrementalEncoding. r=nbp https://hg.mozilla.org/integration/autoland/rev/cd08744153c1 Part 3: Use JS::CompileToStencilOffThread instead of JS::CompileOffThread in ScriptLoader. r=nbp https://hg.mozilla.org/integration/autoland/rev/8c30710801e8 Part 4: Remove stencil option mismatch check in testing function. r=nbp https://hg.mozilla.org/integration/autoland/rev/2e8c1adde5bb Part 5: Remove shell offThreadCompileScript. r=nbp https://hg.mozilla.org/integration/autoland/rev/fdbb03b6d16d Part 6: Remove JS::CompileOffThread. r=nbp https://hg.mozilla.org/integration/autoland/rev/34f47b8fad24 Part 7: Add JS::CompileModuleToStencilOffThread. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/b5604dcc16a4 Part 8: Replace shell offThreadCompileModule with offThreadCompileModuleToStencil. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/0fb4e685ee60 Part 9: Remove JS::CompileOffThreadModule. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/46ffc06461cc Part 10: Fix storageType for decoded stencil without borrowBuffer. r=nbp https://hg.mozilla.org/integration/autoland/rev/e05713ddea2b Part 11: Add JS::DecodeStencilOffThread. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/d35d239bf1cf Part 12: Replace shell offThreadDecodeScript with offThreadDecodeStencil. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/4d15a17ce581 Part 13: Remove JS::DecodeOffThreadScript. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/8de1c9e14cf3 Part 14: Remove JSScript-related methods from ParseTask. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/1c2988344c44 Part 15: Use consistent name for decode multi stencils API. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/1a07d4426d65 Part 16: Use CompilationStencil in helper threads. r=tcampbell
Flags: needinfo?(arai.unmht)
Regressions: 1745527
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: