Skip to content

Commit 4d46ce4

Browse files
perf(javascript): keep no list for a token gap holding no comments (#22491)
Asking for the comments before a token the parser had read past stored the shared empty list under its index, growing a holey array to the token count: 28 MB per minify of typescript.js. The empty list is now returned without being kept.
1 parent c47682f commit 4d46ce4

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13600,10 +13600,12 @@ const installFusedParse = (modules) => {
1360013600
}
1360113601
const known = lists[index];
1360213602
if (known !== undefined) return known;
13603-
// A gap the parser has not read past gains its comments after this, so it
13604-
// is given a list of its own to gain them in; one already read and holding
13605-
// none shares the empty list with every other.
13606-
const list = index < count ? NO_COMMENTS : [];
13603+
// A gap already read past holds none: it shares the empty list, which is
13604+
// not kept, as most gaps are asked for once. One not read past gains its
13605+
// comments after this, so it is given a list of its own to gain them in.
13606+
if (index < count) return NO_COMMENTS;
13607+
/** @type {EXPECTED_ANY[]} */
13608+
const list = [];
1360713609
lists[index] = list;
1360813610
return list;
1360913611
};

0 commit comments

Comments
 (0)