tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 7fa3a4ebaf7e4ee800d55b74ead6913e389e333b
parent a18ff7b13c8f7fe1d833bd6bd22d38b3b051f6e4
Author: Tooru Fujisawa <arai_a@mac.com>
Date:   Wed,  1 Oct 2025 08:51:15 +0000

Bug 1991358 - Part 1: Stop performing JS::FinishCollectingDelazifications/JS::AbortCollectingDelazifications. r=nbp

Now the effect of JS::FinishCollectingDelazifications is only to
stop collecting delazifications, which is not necessary for the consumer's side.
The cost of collecting delazification is also negligible with the
InitialStencilAndDelazifications structure, and also keeping the stencil
reference won't result in too much trouble.

Differential Revision: https://phabricator.services.mozilla.com/D266618

Diffstat:
Mdom/script/ScriptLoader.cpp | 54+-----------------------------------------------------
Mdom/script/ScriptLoader.h | 6------
2 files changed, 1 insertion(+), 59 deletions(-)

diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp @@ -23,7 +23,7 @@ #include "js/Transcoding.h" // JS::TranscodeRange, JS::TranscodeResult, JS::IsTranscodeFailureResult #include "js/Utility.h" #include "js/experimental/CompileScript.h" // JS::FrontendContext, JS::NewFrontendContext, JS::DestroyFrontendContext, JS::SetNativeStackQuota, JS::ThreadStackQuotaForSize, JS::CompilationStorage, JS::CompileGlobalScriptToStencil, JS::CompileModuleScriptToStencil, JS::DecodeStencil, JS::PrepareForInstantiate -#include "js/experimental/JSStencil.h" // JS::Stencil, JS::InstantiationStorage, JS::StartCollectingDelazifications, JS::FinishCollectingDelazifications, JS::AbortCollectingDelazifications, JS::IsStencilCacheable +#include "js/experimental/JSStencil.h" // JS::Stencil, JS::InstantiationStorage, JS::StartCollectingDelazifications, JS::IsStencilCacheable #include "js/loader/LoadedScript.h" #include "js/loader/ModuleLoadRequest.h" #include "js/loader/ModuleLoaderBase.h" @@ -3637,8 +3637,6 @@ void ScriptLoader::UpdateCache() { MOZ_ASSERT(!IsWebExtensionRequest(request), "Bytecode for web extension content scrips is not cached"); - FinishCollectingDelazifications(aes.cx(), request); - // The bytecode encoding is performed only when there was no // bytecode stored in the necko cache. // @@ -3653,29 +3651,6 @@ void ScriptLoader::UpdateCache() { } } -void ScriptLoader::FinishCollectingDelazifications( - JSContext* aCx, ScriptLoadRequest* aRequest) { - RefPtr<JS::Stencil> stencil; - bool result; - if (aRequest->IsModuleRequest()) { - aRequest->mScriptForCache = nullptr; - ModuleScript* moduleScript = aRequest->AsModuleRequest()->mModuleScript; - JS::Rooted<JSObject*> module(aCx, moduleScript->ModuleRecord()); - result = JS::FinishCollectingDelazifications(aCx, module, - getter_AddRefs(stencil)); - } else { - JS::Rooted<JSScript*> script(aCx, aRequest->mScriptForCache); - aRequest->mScriptForCache = nullptr; - result = JS::FinishCollectingDelazifications(aCx, script, - getter_AddRefs(stencil)); - } - if (!result) { - JS_ClearPendingException(aCx); - return; - } - MOZ_ASSERT(stencil == aRequest->GetStencil()); -} - void ScriptLoader::EncodeBytecodeAndSave( JSContext* aCx, JS::loader::LoadedScript* aLoadedScript) { MOZ_ASSERT(aLoadedScript->HasDiskCacheReference()); @@ -3757,39 +3732,12 @@ void ScriptLoader::GiveUpCaching() { // to avoid queuing more scripts. mGiveUpCaching = true; - // Ideally we prefer to properly end the incremental encoder, such that we - // would not keep a large buffer around. If we cannot, we fallback on the - // removal of all request from the current list and these large buffers would - // be removed at the same time as the source object. - nsCOMPtr<nsIScriptGlobalObject> globalObject = GetScriptGlobalObject(); - AutoAllowLegacyScriptExecution exemption; - Maybe<AutoEntryScript> aes; - - if (globalObject) { - nsCOMPtr<nsIScriptContext> context = globalObject->GetScriptContext(); - if (context) { - aes.emplace(globalObject, "give-up bytecode encoding", true); - } - } - while (!mCachingQueue.isEmpty()) { RefPtr<ScriptLoadRequest> request = mCachingQueue.StealFirst(); LOG(("ScriptLoadRequest (%p): Cannot serialize bytecode", request.get())); TRACE_FOR_TEST_NONE(request, "scriptloader_bytecode_failed"); MOZ_ASSERT(!IsWebExtensionRequest(request)); - if (aes.isSome()) { - if (request->IsModuleRequest()) { - ModuleScript* moduleScript = request->AsModuleRequest()->mModuleScript; - JS::Rooted<JSObject*> module(aes->cx(), moduleScript->ModuleRecord()); - JS::AbortCollectingDelazifications(module); - } else { - JS::Rooted<JSScript*> script(aes->cx(), request->mScriptForCache); - request->mScriptForCache = nullptr; - JS::AbortCollectingDelazifications(script); - } - } - request->getLoadedScript()->DropDiskCacheReference(); } diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h @@ -772,12 +772,6 @@ class ScriptLoader final : public JS::loader::ScriptLoaderInterface { void UpdateCache(); /** - * Finish collecting the delazifications and return the stencil. - */ - void FinishCollectingDelazifications(JSContext* aCx, - ScriptLoadRequest* aRequest); - - /** * Encode the stencils and save the bytecode to the necko cache. */ void EncodeBytecodeAndSave(JSContext* aCx,