Commit 0b5b8066 authored by Ted Campbell's avatar Ted Campbell
Browse files

Bug 1600705 - Avoid storing nullptr closed-over-bindings data for LazyScripts. r=jorendorff

The closed-over-binding data is generated for each scope with a nullptr
delimiter per scope. This is wasteful when there are no closed-over bindings.
This patch removes trailing nullptr entries and for leaf-functions may result
in the script-data allocation being avoided altogether.

The FullParseHandler::nextLazyClosedOverBinding() will return nullptr after
the end of the gcthings data so that the delazification process is otherwise
unchanged.

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

--HG--
extra : moz-landing-system : lando
parent e6a17a63
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -1056,10 +1056,16 @@ class FullParseHandler {
                .as<JSFunction>();
  }
  JSAtom* nextLazyClosedOverBinding() {
    auto gcthings = lazyOuterFunction_->gcthings();

    // Trailing nullptrs were elided in PerHandlerParser::finishFunction().
    if (lazyClosedOverBindingIndex >= gcthings.Length()) {
      return nullptr;
    }

    // These entries are either JSAtom* or nullptr, so use the 'asCell()'
    // accessor which is faster.
    gc::Cell* cell =
        lazyOuterFunction_->gcthings()[lazyClosedOverBindingIndex++].asCell();
    gc::Cell* cell = gcthings[lazyClosedOverBindingIndex++].asCell();
    MOZ_ASSERT_IF(cell, cell->is<JSAtom>());
    return static_cast<JSAtom*>(cell);
  }
+9 −0
Original line number Diff line number Diff line
@@ -1739,6 +1739,15 @@ bool PerHandlerParser<SyntaxParseHandler>::finishFunction(
    return false;
  }

  // Elide nullptr sentinels from end of binding list. These are inserted for
  // each scope regardless of if any bindings are actually closed over.
  {
    AtomVector& COB = pc_->closedOverBindingsForLazy();
    while (!COB.empty() && (COB.back() == nullptr)) {
      COB.popBack();
    }
  }

  // There are too many bindings or inner functions to be saved into the
  // LazyScript. Do a full parse.
  if (pc_->closedOverBindingsForLazy().length() >=
+0 −2
Original line number Diff line number Diff line
@@ -4210,8 +4210,6 @@ PrivateScriptData::PrivateScriptData(uint32_t ngcthings)

  // Layout and initialize the gcthings array.
  {
    MOZ_ASSERT(ngcthings > 0);

    static_assert(alignof(PrivateScriptData) >= alignof(JS::GCCellPtr),
                  "Incompatible alignment");
    initElements<JS::GCCellPtr>(cursor, ngcthings);