Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/jekyll-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,11 @@ jobs:
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: docs/package-lock.json
cache-dependency-path: package-lock.json
- name: Install Node.js dependencies and Chromium
run: |
npm ci
npx puppeteer browsers install chrome --install-deps
working-directory: ./docs
sudo npx puppeteer browsers install chrome --install-deps
- name: Render book PDF
run: |
mkdir -p _pdf
Expand Down
6 changes: 3 additions & 3 deletions docs/book.bat
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ if not exist _site-pdf\book.html (
echo _site-pdf\book.html not found. Run build.bat first.
exit /b 1
)
if not exist node_modules\puppeteer\package.json (
echo Installing docs\ dependencies...
call npm install
if not exist ..\node_modules\puppeteer\package.json (
echo Installing dependencies...
pushd .. && call npm install && popd
if errorlevel 1 exit /b 1
)
if not exist _pdf mkdir _pdf
Expand Down
39 changes: 39 additions & 0 deletions docs/lib/paged.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@
let added = [];

let fragment = document.createDocumentFragment();
// [PATCH: findRef fast-path] Carry an indexOfRefs alongside the
// fragment so callers' findElement(*, fragment) lookups hit the
// fast path, and so the caller can merge this into dest.indexOfRefs
// in one pass after dest.appendChild(fragment). Without this, every
// findElement(rebuiltAncestor, dest) on a subsequent append() call
// falls through to dest.querySelector("[data-ref='...']") — measured
// as 15,767 dictMiss calls ≈ 2.5 s of render on the 1651-page book.
fragment.indexOfRefs = {};

// Handle rowspan on table
if (node.nodeName === "TR") {
Expand Down Expand Up @@ -385,6 +393,14 @@
}
added.push(parent);

// [PATCH: findRef fast-path] Record the rebuilt clone in the
// fragment's indexOfRefs so findElement(*, fragment) hits the
// fast path and so dest.indexOfRefs can be updated cheaply by
// the caller (see Layout.append's rebuild branch).
if (parent.dataset && parent.dataset.ref) {
fragment.indexOfRefs[parent.dataset.ref] = parent;
}

// rebuild table rows
if (parent.nodeName === "TD" && ancestor.parentElement.contains(ancestor)) {
let td = ancestor;
Expand Down Expand Up @@ -1716,6 +1732,17 @@
}

dest.appendChild(fragment);

// [PATCH: findRef fast-path] Merge the rebuilt fragment's
// indexOfRefs into dest's. Without this, every subsequent
// findElement(rebuiltAncestor, dest) on this page misses
// the dict and falls through to dest.querySelector.
if (fragment.indexOfRefs) {
if (!dest.indexOfRefs) dest.indexOfRefs = {};
for (const k in fragment.indexOfRefs) {
dest.indexOfRefs[k] = fragment.indexOfRefs[k];
}
}
} else {
dest.appendChild(clone);
}
Expand Down Expand Up @@ -2587,6 +2614,14 @@
false
);

// [PATCH: findRef fast-path] Populate content.indexOfRefs as we walk
// so every later findElement(*, source) call hits the dict instead
// of falling through to source.querySelector("[data-ref='X']"),
// which scans the entire source DOM (thousands of nodes). Measured
// as 848 + 42 noDict calls in createBreakToken ≈ 1+ s of render on
// the 1651-page book.
if (!content.indexOfRefs) content.indexOfRefs = {};

let node = treeWalker.nextNode();
while(node) {

Expand All @@ -2602,6 +2637,10 @@
// node.setAttribute("data-children", node.childNodes.length);

// node.setAttribute("data-text", node.textContent.trim().length);

// [PATCH: findRef fast-path] record after data-ref is guaranteed.
content.indexOfRefs[node.getAttribute("data-ref")] = node;

node = treeWalker.nextNode();
}
}
Expand Down
11 changes: 0 additions & 11 deletions docs/package.json

This file was deleted.

Loading
Loading