File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 26112611 // dicts at their own init sites. `findRef` does `arr[ref]` either
26122612 // way -- V8 coerces the decimal-string ref to an array index
26132613 // transparently, so no caller-side branch is needed.
2614- if (!content.indexOfRefs) content.indexOfRefs = [];
2614+ //
2615+ // [PATCH: source-indexOfRefs-presize] Size the array up front
2616+ // from the live HTMLCollection's .length. V8 grows arrays
2617+ // geometrically -- writing slots 1..N via doubling does
2618+ // log2(N) backing-store reallocations, each allocating the
2619+ // new store and orphaning the old (transient bytes ~= 2x the
2620+ // final size). Pre-sizing skips all of that.
2621+ if (!content.indexOfRefs) {
2622+ const elementCount = content.getElementsByTagName ? content.getElementsByTagName("*").length : 0;
2623+ content.indexOfRefs = new Array(elementCount + 1);
2624+ }
26152625
26162626 let node = treeWalker.nextNode();
26172627 while(node) {
You can’t perform that action at this time.
0 commit comments