tor-browser

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

commit e17241ae51ed1929cf6e0ed3c77b410fd3cb3506
parent fb321bdf9c63c3b21e158571d2f0349132155212
Author: Tooru Fujisawa <arai_a@mac.com>
Date:   Wed, 17 Dec 2025 18:38:05 +0000

Bug 2006042 - Show script instantiation in the profiler, separately than compile/decode. r=nbp

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

Diffstat:
Mdom/script/ScriptLoader.cpp | 36++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp @@ -3090,9 +3090,14 @@ static void InstantiateStencil( JS::MutableHandle<JSScript*> aScript, JS::Handle<JS::Value> aDebuggerPrivateValue, JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv, + const nsAutoCString& aProfilerLabelString, JS::InstantiationStorage* aStorage = nullptr, CollectDelazifications aCollectDelazifications = CollectDelazifications::No) { + AUTO_PROFILER_MARKER_TEXT("ScriptInstantiation", JS, + MarkerInnerWindowIdFromJSContext(aCx), + aProfilerLabelString); + JS::InstantiateOptions instantiateOptions(aCompileOptions); JS::Rooted<JSScript*> script( aCx, JS::InstantiateGlobalStencil(aCx, instantiateOptions, aStencil, @@ -3149,22 +3154,25 @@ void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource( InstantiateStencil(aCx, aCompileOptions, stencil, aScript, aDebuggerPrivateValue, aDebuggerIntroductionScript, - aRv, &storage); + aRv, profilerLabelString, &storage); } else { LOG(("ScriptLoadRequest (%p): Decode and Execute", aRequest)); - AUTO_PROFILER_MARKER_TEXT("DecodeStencilMainThread", JS, - MarkerInnerWindowIdFromJSContext(aCx), - profilerLabelString); RefPtr<JS::Stencil> stencil; - Decode(aCx, aCompileOptions, aRequest->SerializedStencil(), stencil, aRv); + { + AUTO_PROFILER_MARKER_TEXT("DecodeStencilMainThread", JS, + MarkerInnerWindowIdFromJSContext(aCx), + profilerLabelString); + Decode(aCx, aCompileOptions, aRequest->SerializedStencil(), stencil, + aRv); + } if (stencil) { aRequest->SetStencil(stencil); InstantiateStencil(aCx, aCompileOptions, stencil, aScript, aDebuggerPrivateValue, aDebuggerIntroductionScript, - aRv); + aRv, profilerLabelString); } } @@ -3200,7 +3208,7 @@ void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource( InstantiateStencil(aCx, aCompileOptions, stencil, aScript, aDebuggerPrivateValue, aDebuggerIntroductionScript, aRv, - &storage, collectDelazifications); + profilerLabelString, &storage, collectDelazifications); } else { // Main thread parsing (inline and small scripts) LOG(("ScriptLoadRequest (%p): Compile And Exec", aRequest)); @@ -3209,13 +3217,13 @@ void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource( aRv = aRequest->GetScriptSource(aCx, &maybeSource, aRequest->mLoadContext.get()); if (!aRv.Failed()) { - AUTO_PROFILER_MARKER_TEXT("ScriptCompileMainThread", JS, - MarkerInnerWindowIdFromJSContext(aCx), - profilerLabelString); - RefPtr<JS::Stencil> stencil; ErrorResult erv; auto compile = [&](auto& source) { + AUTO_PROFILER_MARKER_TEXT("ScriptCompileMainThread", JS, + MarkerInnerWindowIdFromJSContext(aCx), + profilerLabelString); + stencil = CompileGlobalScriptToStencil(aCx, aCompileOptions, source); if (!stencil) { erv.NoteJSContextException(aCx); @@ -3230,7 +3238,7 @@ void ScriptLoader::InstantiateClassicScriptFromMaybeEncodedSource( InstantiateStencil(aCx, aCompileOptions, stencil, aScript, aDebuggerPrivateValue, aDebuggerIntroductionScript, - erv, /* aStorage = */ nullptr, + erv, profilerLabelString, /* aStorage = */ nullptr, collectDelazifications); } @@ -3245,6 +3253,9 @@ void ScriptLoader::InstantiateClassicScriptFromCachedStencil( JS::MutableHandle<JSScript*> aScript, JS::Handle<JS::Value> aDebuggerPrivateValue, JS::Handle<JSScript*> aDebuggerIntroductionScript, ErrorResult& aRv) { + nsAutoCString profilerLabelString; + aRequest->GetScriptLoadContext()->GetProfilerLabel(profilerLabelString); + CalculateCacheFlag(aRequest); MOZ_ASSERT(aRequest->PassedConditionForMemoryCache()); @@ -3260,6 +3271,7 @@ void ScriptLoader::InstantiateClassicScriptFromCachedStencil( // queued multiple times. InstantiateStencil(aCx, aCompileOptions, aStencil, aScript, aDebuggerPrivateValue, aDebuggerIntroductionScript, aRv, + profilerLabelString, /* aStorage = */ nullptr, CollectDelazifications::Yes); }