Skip to content

Compute operator bounding boxes in the worker - #22289

Open
calixteman wants to merge 3 commits into
mozilla:masterfrom
calixteman:bbox_worker
Open

calixteman wants to merge 3 commits into
mozilla:masterfrom
calixteman:bbox_worker

Conversation

@calixteman

Copy link
Copy Markdown
Contributor

Compute operator bounds and propagate them to dependencies in the worker. Send packed bounds to the display layer for partial rendering and debugger highlights.

Remove display-side bounding-box tracking and recordOperations, and enable optimized partial rendering by default.

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Viewer preview

Commit 34f4838 (build logs).

Viewer Build Preview
Modern (gulp generic) ✅ viewer.html
Legacy (gulp generic-legacy) ✅ viewer.html

Previews are removed when the PR closes and may be pruned after 30 days without an update.

@codecov-commenter

codecov-commenter commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.38650% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.53%. Comparing base (7fed67d) to head (34f4838).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
src/core/operator_list_bbox_tracker.js 99.52% 3 Missing ⚠️
src/display/api.js 88.88% 1 Missing ⚠️
src/display/canvas_images_tracker.js 97.91% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22289      +/-   ##
==========================================
+ Coverage   90.46%   90.53%   +0.06%     
==========================================
  Files         277      279       +2     
  Lines       68317    68495     +178     
==========================================
+ Hits        61805    62010     +205     
+ Misses       6512     6485      -27     
Flag Coverage Δ
browsertest 66.47% <91.65%> (+0.16%) ⬆️
fonttest 9.01% <0.00%> (+<0.01%) ⬆️
integrationtest 69.86% <84.41%> (+0.39%) ⬆️
unittest 61.02% <83.06%> (+0.11%) ⬆️
unittestcli 58.75% <77.88%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 3.78%

⚡ 3 improved benchmarks
❌ 6 regressed benchmarks
✅ 78 untouched benchmarks
⏩ 87 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ PartialEvaluator.buildPath: lines (bug1743245.pdf) 15.4 ms 18.5 ms -16.68%
❌ FlateStream: content streams (tracemonkey.pdf) 39.7 ms 43 ms -7.61%
❌ OperatorList.addOp: paths and clips (bug1703683_page2_reduced.pdf) 6 ms 6.5 ms -6.43%
❌ Lexer.getObj: text (issue12963.pdf) 18.7 ms 19.9 ms -5.88%
❌ PartialEvaluator.buildPath: curves (issue12705.pdf) 1.1 ms 1.2 ms -5.86%
❌ EvaluatorPreprocessor.read: paths (bug1743245.pdf) 55.7 ms 58.9 ms -5.33%
⚡ createImage: signature (samplesignature.png) 160.7 ms 152.3 ms +5.48%
⚡ Pattern.parseShading: function-based, PostScript (function_based_shading.pdf) 46.1 ms 43.8 ms +5.37%
⚡ RunLengthStream (issue19326.pdf) 494.8 µs 470 µs +5.27%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing calixteman:bbox_worker (34f4838) with master (11d4a2e)

Open in CodSpeed

Footnotes

  1. 87 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

* Writes the transformed rectangle's axis-aligned bounds into `output`.
* @returns {boolean} Whether the result is a valid box.
*/
function transformRect(x0, y0, x1, y1, matrix, output) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the exception of the last line, this function looks like a verbatim copy of Util.axialAlignedBoundingBox?

Comment thread src/core/operator_list_bbox_tracker.js Outdated
);
}

function intersectBBoxes(first, second) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the exception of the last line, how similar is this to Util.intersect?

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 21, 2026
Comment thread src/display/display_utils.js Outdated
* Operation bounds stored as `[minX, minY, maxX, maxY]` bytes in 1/256 of the
* page view box. Decoding adds one unit to the upper bounds.
*/
class OperatorBBoxes {

@Snuffleupagus Snuffleupagus Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this class unused in the renderer-worker?
If so you might want to place this in its own file instead, to avoid this code being bundled into the pdf.renderer.mjs file.

Comment thread web/app_options.js
{
/** @type {boolean} */
value: false,
value: true,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this perhaps be enabled by default in the PDFViewer and BasePDFPageView classes as well?

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 21, 2026
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 21, 2026

@Snuffleupagus Snuffleupagus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this made Util.multiplyByDOMMatrix unused, so that can probably be removed now?

Comment thread src/shared/util.js Outdated
@@ -802,46 +790,53 @@ class Util {
// Applies the transform to the rectangle and finds the minimum axially
// aligned bounding box.
static axialAlignedBoundingBox(rect, transform, output) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably better suited for a follow-up, but should all existing Util.axialAlignedBoundingBox calls be replaced with Util.transformedRectBoundingBox instead?

Propagate bounds to operator dependencies and send packed boxes with the
final operator-list chunk. Expose them through OperatorBBoxes.
Migrate operation filters and debugger highlights to worker bounds.
Remove display-side bounding-box tracking and recordOperations.
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants