Closed Bug 1436400 Opened 8 years ago Closed 4 years ago

Cache module scripts in the bytecode cache

Categories

(Core :: DOM: Core & HTML, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
100 Branch
Tracking Status
firefox100 --- fixed

People

(Reporter: jonco, Assigned: arai)

References

Details

Attachments

(14 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
The bytecode cache currently only supports classic scripts. We should extend this to support JS modules too.
Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Depends on: 1757597

As a preparation to add bytecode case to CompileOrFinishModuleScript, removed
the shared nsresult variable and make each branch directly return, and also
do early return for error case.

Depends on D140289

To add conditional JS::StartIncrementalEncoding, and also to add a bytecode
decoding branch, replace nsJSUtils::CompileModule with raw JSAPI calls with
Stencil.

Depends on D140290

Module bytecode should use different MIME type, to avoid mixing up script/module
bytecodes for single JS file.

This patch adds a static method that simply returns the current bytecode MIME
type.
The later patch adds a new MIME type for module bytecode and modify the
ScriptLoader::BytecodeMimeTypeFor method to return corresponding MIME type.

Depends on D140291

Module's ScriptSlot is cleared after executing the top-level script.
In order to skip modules imported multiple times when encoding, added
JS::IsExecutedModule.

Depends on D140293

As a preparation to use the bytecode encoding in the module evaluation code,
ScriptLoader::MaybePrepareForBytecodeEncoding is split into 2 parts:

  • one for performing preparation before executing script
  • one for queuing the request for bytecode encoding after executing script

In module's case, the bytecode encoding handling must be done on the entire
import tree, and also the module object's ScriptSlot is cleared on execution.
So, the script reference must be copied to the corresponding script load request
field before execution, and the script source must be queued for bytecode
encoding after executing the top-level script, so that incremental encoding
reflects functions called there.

Depends on D140294

The module scripts are scanned immediately before executing, and if the
module script is not yet executed, and it matches the requirement for encoding
(size, fetch count, etc), it's marked as encode,
and they're scanned again immediately after executing, and marked scripts are
queued for bytecode encoding.

This patch doesn't actually enable the encoding, given ShouldCacheBytecode
returns false because the caching is not enabled for the channel and
GetCacheTokenFetchCount fails.

Depends on D140295

Attachment #9266424 - Attachment description: Bug 1436400 - Part 6: Add JS::IsExecutedModule. r?jonco! → Bug 1436400 - Part 6: Add JS::IsModuleEvaluated. r?jonco!

After enabling bytecode cache for module script, we need to handle
the SRI mismatch on bytecode cache, that requires reloading the script source
again.

Depends on D140296

Attachment #9266427 - Attachment description: Bug 1436400 - Part 9: Support bytecode cache for module script. r?nbp! → Bug 1436400 - Part 10: Support bytecode cache for module script. r?nbp!

TODO: add testcase with <link rel="preload">

(In reply to Tooru Fujisawa [:arai] from comment #16)

TODO: add testcase with <link rel="preload">

This was unrelated here.
will post test with iframes.

Blocks: 1759206
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/40b474d430e9 Part 1: Remove Unused parameter from ExecuteCompiledScript. r=jonco https://hg.mozilla.org/integration/autoland/rev/e38a959648e1 Part 2: Simplify ModuleLoader::CompileOrFinishModuleScript code flow. r=jonco https://hg.mozilla.org/integration/autoland/rev/dd0fea93bcd7 Part 3: Remove nsJSUtils::CompileModule and directly use JSAPI with stencil. r=nbp https://hg.mozilla.org/integration/autoland/rev/b1c2084042fa Part 4: Add ScriptLoader::BytecodeMimeTypeFor static method to get bytecode MIME type for given request. r=nbp https://hg.mozilla.org/integration/autoland/rev/dd2bb1b46f75 Part 5: Add bytecode MIME type for regular script and module. r=nbp https://hg.mozilla.org/integration/autoland/rev/001d8528ff96 Part 6: Add JS::IsModuleEvaluated. r=jonco https://hg.mozilla.org/integration/autoland/rev/cce080064d82 Part 7: Split ScriptLoader::MaybePrepareForBytecodeEncoding into 2 parts. r=nbp https://hg.mozilla.org/integration/autoland/rev/8f894ea40eb2 Part 8: Add code path for bytecode encoding module scripts. r=nbp https://hg.mozilla.org/integration/autoland/rev/c33620854115 Part 9: Support restarting module load request. r=jonco https://hg.mozilla.org/integration/autoland/rev/6f473bcf809a Part 10: Support bytecode cache for module script. r=nbp https://hg.mozilla.org/integration/autoland/rev/561aeb550892 Part 11: Modify test_script_loader_js_cache.html to test basic module script. r=nbp https://hg.mozilla.org/integration/autoland/rev/5ac844508d8b Part 12: Add testcases for bytecode encoding and module with import. r=nbp https://hg.mozilla.org/integration/autoland/rev/ffd9ddcef6b0 Part 13: Add testcases for bytecode encoding and module with SRI fallback. r=nbp https://hg.mozilla.org/integration/autoland/rev/4be29c1eb5bc Part 14: Add testcases for bytecode encoding and module with iframes. r=nbp
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/ee0194a35613 Part 1: Remove Unused parameter from ExecuteCompiledScript. r=jonco https://hg.mozilla.org/integration/autoland/rev/a4c1a6688a8c Part 2: Simplify ModuleLoader::CompileOrFinishModuleScript code flow. r=jonco https://hg.mozilla.org/integration/autoland/rev/3a587ff43de9 Part 3: Remove nsJSUtils::CompileModule and directly use JSAPI with stencil. r=nbp https://hg.mozilla.org/integration/autoland/rev/dc2dc93cafaf Part 4: Add ScriptLoader::BytecodeMimeTypeFor static method to get bytecode MIME type for given request. r=nbp https://hg.mozilla.org/integration/autoland/rev/d8dbb7131db9 Part 5: Add bytecode MIME type for regular script and module. r=nbp https://hg.mozilla.org/integration/autoland/rev/b5378c419f06 Part 6: Add JS::IsModuleEvaluated. r=jonco https://hg.mozilla.org/integration/autoland/rev/d4847bfb8b12 Part 7: Split ScriptLoader::MaybePrepareForBytecodeEncoding into 2 parts. r=nbp https://hg.mozilla.org/integration/autoland/rev/f43d53e2b41e Part 8: Add code path for bytecode encoding module scripts. r=nbp https://hg.mozilla.org/integration/autoland/rev/53bd843e4e47 Part 9: Support restarting module load request. r=jonco https://hg.mozilla.org/integration/autoland/rev/03c914329e22 Part 10: Support bytecode cache for module script. r=nbp https://hg.mozilla.org/integration/autoland/rev/f2ff76a6acf5 Part 11: Modify test_script_loader_js_cache.html to test basic module script. r=nbp https://hg.mozilla.org/integration/autoland/rev/2408f4c4260a Part 12: Add testcases for bytecode encoding and module with import. r=nbp https://hg.mozilla.org/integration/autoland/rev/38be4c94b912 Part 13: Add testcases for bytecode encoding and module with SRI fallback. r=nbp https://hg.mozilla.org/integration/autoland/rev/123ba639073b Part 14: Add testcases for bytecode encoding and module with iframes. r=nbp
Flags: needinfo?(arai.unmht)
Regressions: 1787529
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: