Skip to content

[api-minor] Replace the CMapReaderFactory, StandardFontDataFactory, and WasmFactory API options with a single factory/option#20949

Merged
timvandermeij merged 1 commit intomozilla:masterfrom
Snuffleupagus:BinaryDataFactory-2
Mar 22, 2026
Merged

[api-minor] Replace the CMapReaderFactory, StandardFontDataFactory, and WasmFactory API options with a single factory/option#20949
timvandermeij merged 1 commit intomozilla:masterfrom
Snuffleupagus:BinaryDataFactory-2

Conversation

@Snuffleupagus
Copy link
Copy Markdown
Collaborator

@Snuffleupagus Snuffleupagus commented Mar 22, 2026

Currently we have no less than three different, but very similar, factories for reading built-in CMap files, standard font files, and wasm files on the main-thread.[1]
These factories were added at different points in time, since I cannot imagine that we'd add essentially three copies of the same code otherwise.

Nowadays these factories are often not even used[2], since worker-thread fetching is used whenever possible to improve performance. In particular, they will only be used when either:

  • The PDF.js library runs in Node.js environments.
  • The user manually sets useWorkerFetch = false when calling getDocument.
  • The user provides custom CMapReaderFactory, StandardFontDataFactory, and/or WasmFactory instances when calling getDocument.

By replacing these factories with a single new BinaryDataFactory factory/option the number of getDocument options are thus reduced, which cannot hurt.
This also reduces the total bundle-size of the Firefox PDF Viewer a little bit, and it slightly reduces the number of import maps that need to be maintained.

Please note: For users that provide custom CMapReaderFactory, StandardFontDataFactory, and WasmFactory instances when calling getDocument this will be a breaking change, however it's unlikely that (many) such users exist.
(The internal format data-format of CMapReaderFactory was changed in PR #18951, and there hasn't been a single question/complaint about it in well over a year.)


[1] Any new functionality could easily lead to more such factories being added in the future, which wouldn't be great.

[2] Note that the Firefox PDF Viewer no longer use these factories, since it "forcibly" sets useWorkerFetch = true during building.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 88.78505% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.53%. Comparing base (9fa5cb9) to head (3a372fd).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/display/binary_data_factory.js 87.34% 10 Missing ⚠️
src/core/jpx.js 0.00% 1 Missing ⚠️
src/display/api.js 95.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20949      +/-   ##
==========================================
- Coverage   62.61%   62.53%   -0.08%     
==========================================
  Files         174      172       -2     
  Lines      121947   121785     -162     
==========================================
- Hits        76355    76162     -193     
- Misses      45592    45623      +31     
Flag Coverage Δ
fonttest 7.66% <ø> (ø)
unittestcli 62.51% <88.78%> (-0.08%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

…`, and `WasmFactory` API options with a single factory/option

Currently we have no less than three different, but very similar, factories for reading built-in CMap files, standard font files, and wasm files on the main-thread.[1]
These factories were added at different points in time, since I cannot imagine that we'd add essentially three copies of the same code otherwise.

Nowadays these factories are often not even used[2], since worker-thread fetching is used whenever possible to improve performance. In particular, they will *only* be used when either:
 - The PDF.js library runs in Node.js environments.
 - The user manually sets `useWorkerFetch = false` when calling `getDocument`.
 - The user provides custom `CMapReaderFactory`, `StandardFontDataFactory`, and/or `WasmFactory` instances when calling `getDocument`.

By replacing these factories with *a single* new `BinaryDataFactory` factory/option the number of `getDocument` options are thus reduced, which cannot hurt.
This also reduces the total bundle-size of the Firefox PDF Viewer a little bit, and it slightly reduces the number of import maps that need to be maintained.

*Please note:* For users that provide custom `CMapReaderFactory`, `StandardFontDataFactory`, and `WasmFactory` instances when calling `getDocument` this will be a breaking change, however it's unlikely that (many) such users exist.
(The *internal* format data-format of `CMapReaderFactory` was changed in PR 18951, and there hasn't been a single question/complaint about it in well over a year.)

---

[1] Any new functionality could easily lead to more such factories being added in the future, which wouldn't be great.

[2] Note that the Firefox PDF Viewer no longer use these factories, since it "forcibly" sets `useWorkerFetch = true` during building.
@Snuffleupagus
Copy link
Copy Markdown
Collaborator Author

/botio test

@moz-tools-bot
Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/146549f862dbb6b/output.txt

@moz-tools-bot
Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.193.163.58:8877/f7412830035d463/output.txt

@moz-tools-bot
Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/146549f862dbb6b/output.txt

Total script time: 45.96 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: Passed

@moz-tools-bot
Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/f7412830035d463/output.txt

Total script time: 72.55 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: Passed

@Snuffleupagus Snuffleupagus marked this pull request as ready for review March 22, 2026 17:00
@timvandermeij timvandermeij merged commit 1756b48 into mozilla:master Mar 22, 2026
15 checks passed
@timvandermeij
Copy link
Copy Markdown
Contributor

Nice simplification; thanks!

@Snuffleupagus Snuffleupagus deleted the BinaryDataFactory-2 branch March 22, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants