Skip to content

Avoid quadratic autolinking on pages with many links - #22319

Merged
calixteman merged 2 commits into
mozilla:masterfrom
calixteman:autolinker_single_range
Oct 23, 2026
Merged

calixteman merged 2 commits into
mozilla:masterfrom
calixteman:autolinker_single_range

Conversation

@calixteman

Copy link
Copy Markdown
Contributor

Autolinker.processLinks was quadratic in the number of links on a page:

  • it created one Range per link. In Firefox, each attribute write costs time proportional to the number of live ranges, so the annotation layer's aria-owns updates became quadratic;
  • it called _convertMatches once per link, and each call rescanned the text items from the start.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Viewer preview

🗑️ Viewer previews removed.

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

codecov-commenter commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.46%. Comparing base (5b4187c) to head (88a0428).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22319      +/-   ##
==========================================
- Coverage   90.47%   90.46%   -0.01%     
==========================================
  Files         277      277              
  Lines       68313    68317       +4     
==========================================
+ Hits        61803    61804       +1     
- Misses       6510     6513       +3     
Flag Coverage Δ
browsertest 66.32% <0.00%> (-0.01%) ⬇️
integrationtest 69.47% <100.00%> (+0.02%) ⬆️
unittest 60.90% <0.00%> (-0.02%) ⬇️
unittestcli 58.64% <0.00%> (-0.02%) ⬇️

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 23, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 1.75%

⚡ 3 improved benchmarks
❌ 6 regressed benchmarks
✅ 77 untouched benchmarks
🆕 2 new benchmarks
⏩ 86 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ OperatorList.addOp: paths and clips (bug1703683_page2_reduced.pdf) 5.8 ms 6.6 ms -12.48%
❌ PartialEvaluator.buildPath: curves (issue12705.pdf) 1.2 ms 1.3 ms -11.46%
❌ Ascii85Stream (bug1337429.pdf) 3.4 ms 3.7 ms -7.31%
❌ Parser: parse content stream objects 17.1 ms 18.3 ms -6.5%
❌ EvaluatorPreprocessor.read: text (issue12963.pdf) 32.5 ms 34.8 ms -6.42%
❌ PDFImage.createImageData: ICCBased (issue6931_reduced.pdf) 8.3 ms 8.8 ms -5.75%
⚡ Pattern.parseShading: axial, sampled (bug852992_reduced.pdf) 750 µs 652.9 µs +14.88%
⚡ Pattern.parseShading: function-based, sampled (function_based_shading_cmyk.pdf) 48.8 ms 42.9 ms +13.71%
⚡ Pattern.parseShading: radial (radial_gradients.pdf) 6.8 ms 6.1 ms +10.26%
🆕 Autolinker.processLinks: 10 links in each of 1000 text items N/A 74.2 ms N/A
🆕 Autolinker.processLinks: 2 links in each of 5000 text items N/A 92.4 ms N/A

Tip

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


Comparing calixteman:autolinker_single_range (88a0428) with master (9cac28a)2

Open in CodSpeed

Footnotes

  1. 86 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. ↩

  2. No successful run was found on master (5b4187c) during the generation of this report, so 9cac28a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@calixteman
calixteman merged commit 7fed67d into mozilla:master Oct 23, 2026
18 of 20 checks passed
@calixteman
calixteman deleted the autolinker_single_range branch October 23, 2026 17:59
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 23, 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.

Also, please add the description in #22319 (comment) to the (first) commit message.

r=me, thanks.

Comment thread web/autolinker.js
annotationType: AnnotationType.LINK,
rotation: 0,
...calculateLinkPosition(range, pdfPageView),
// Assigned by AnnotationLayer after overlap filtering.

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.

This is slightly less clear than the old comment, can we please just keep that one instead?

Suggested change
// Assigned by AnnotationLayer after overlap filtering.
// Populated in the annotationLayer to avoid unnecessary object creation,
// since most inferred links overlap existing LinkAnnotations:

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