Closed Bug 1843956 Opened 2 years ago Closed 2 years ago

Do not try to decompress ScriptSource in concurrent delazification

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
117 Branch
Tracking Status
firefox117 --- fixed

People

(Reporter: arai, Assigned: arai)

References

Details

Attachments

(1 file)

DelazifyCanonicalScriptedFunctionImpl can try decompressing the ScriptSource if it's already compressed, and the decompression needs JSContext.

https://searchfox.org/mozilla-central/rev/7a4c08f2c3a895c9dc064734ada320f920250c1f/js/src/frontend/BytecodeCompiler.cpp#1273-1279,1297-1298

template <typename Unit>
static bool DelazifyCanonicalScriptedFunctionImpl(JSContext* cx,
                                                  FrontendContext* fc,
                                                  ScopeBindingCache* scopeCache,
                                                  JS::Handle<JSFunction*> fun,
                                                  JS::Handle<BaseScript*> lazy,
                                                  ScriptSource* ss) {
...
  ScriptSource::PinnedUnits<Unit> units(cx, ss, holder, sourceStart,
                                        sourceLength);

https://searchfox.org/mozilla-central/rev/7a4c08f2c3a895c9dc064734ada320f920250c1f/js/src/vm/JSScript.cpp#1213-1217,1220

template <typename Unit>
ScriptSource::PinnedUnits<Unit>::PinnedUnits(
    JSContext* cx, ScriptSource* source,
    UncompressedSourceCache::AutoHoldEntry& holder, size_t begin, size_t len)
    : PinnedUnitsBase(source) {
...
  units_ = source->units<Unit>(cx, holder, begin, len);

https://searchfox.org/mozilla-central/rev/7a4c08f2c3a895c9dc064734ada320f920250c1f/js/src/vm/JSScript.cpp#1107-1111,1114-1120,1150-1151,1157,1169,1176

template <typename Unit>
const Unit* ScriptSource::units(JSContext* cx,
                                UncompressedSourceCache::AutoHoldEntry& holder,
                                size_t begin, size_t len) {
  MOZ_ASSERT(begin <= length());
...
  if (isUncompressed<Unit>()) {
    const Unit* units = uncompressedData<Unit>()->units();
    if (!units) {
      return nullptr;
    }
    return units + begin;
  }
...
  if (firstChunk == lastChunk) {
    const Unit* units = chunkUnits<Unit>(cx, holder, firstChunk);
...
  }
...
  {
...
    const Unit* units = chunkUnits<Unit>(cx, firstHolder, firstChunk);

and the compression is scheduled when the top-level script is instantiated.

https://searchfox.org/mozilla-central/rev/7a4c08f2c3a895c9dc064734ada320f920250c1f/js/src/frontend/BytecodeCompiler.cpp#440-442,456

bool frontend::InstantiateStencils(JSContext* cx, CompilationInput& input,
                                   const CompilationStencil& stencil,
                                   CompilationGCOutput& gcOutput) {
...
  if (!stencil.source->tryCompressOffThread(cx)) {

https://searchfox.org/mozilla-central/rev/7a4c08f2c3a895c9dc064734ada320f920250c1f/js/src/vm/JSScript.cpp#1376,1418

bool ScriptSource::tryCompressOffThread(JSContext* cx) {
...
  return EnqueueOffThreadCompression(cx, std::move(task));

https://searchfox.org/mozilla-central/rev/7a4c08f2c3a895c9dc064734ada320f920250c1f/js/src/vm/HelperThreads.cpp#2313-2314,2319-2320

bool js::EnqueueOffThreadCompression(JSContext* cx,
                                     UniquePtr<SourceCompressionTask> task) {
...
  auto& pending = HelperThreadState().compressionPendingList(lock);
  if (!pending.append(std::move(task))) {

and the pending compression is started on GC:

https://searchfox.org/mozilla-central/rev/7a4c08f2c3a895c9dc064734ada320f920250c1f/js/src/vm/HelperThreads.cpp#2328,2330

void js::StartHandlingCompressionsOnGC(JSRuntime* runtime) {
...
  HelperThreadState().startHandlingCompressionTasks(

So, the concurrent delazification isn't much necessary after this point.

making the JSContext parameter optional in the ScriptSource helps moving DelazifyTask to FrontendContext.

Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/59609798ba99 Do not decompress source in concurrent delazification. r=nbp
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 117 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: