Skip to content

Avoid some String.fromCharCode calls in the Lexer.prototype.getString method - #22227

Merged
timvandermeij merged 1 commit into
mozilla:masterfrom
Snuffleupagus:Lexer-getString-skip-fromCharCode
Oct 18, 2026
Merged

timvandermeij merged 1 commit into
mozilla:masterfrom
Snuffleupagus:Lexer-getString-skip-fromCharCode

Conversation

@Snuffleupagus

Copy link
Copy Markdown
Collaborator

For a number of known character-sequences we directly push the resulting character, however that's not done for \\, \(, and \) where String.fromCharCode is thus used instead.
Perhaps the idea was that these cases are uncommon in practice, however when parsing and rendering all pages of pdf.pdf (from the test-suite) those cases are hit over 54 000 times. Hence it seems that it cannot hurt to add "fast paths" there as well.

…ing` method

For a number of known character-sequences we directly push the resulting character, however that's not done for `\\`, `\(`, and `\)` where `String.fromCharCode` is thus used instead.
Perhaps the idea was that these cases are uncommon in practice, however when parsing and rendering all pages of `pdf.pdf` (from the test-suite) those cases are hit over `54 000` times. Hence it seems that it cannot hurt to add "fast paths" there as well.
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Reference tests

Results for 50ab00d (run, references from mozilla/pdf.js.refs@c77f4688b3).

Platform Status Tests Total runtime Errors Different FBF No reference Report
Linux ✅ 1398 11m 9s 0 0 0 0
Windows ⚠️ 1398 17m 27s 0 1 0 0 view differences

The report is kept for 30 days and replaced by the next run.

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

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Viewer preview

🗑️ Viewer previews removed.

@codecov-commenter

codecov-commenter commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.42%. Comparing base (157d30e) to head (50ab00d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #22227   +/-   ##
=======================================
  Coverage   90.42%   90.42%           
=======================================
  Files         277      277           
  Lines       68093    68097    +4     
=======================================
+ Hits        61571    61579    +8     
+ Misses       6522     6518    -4     
Flag Coverage Δ
browsertest 66.40% <100.00%> (+0.01%) ⬆️
fonttest 8.97% <0.00%> (-0.01%) ⬇️
integrationtest 69.33% <100.00%> (+0.01%) ⬆️
unittest 60.64% <100.00%> (-0.01%) ⬇️
unittestcli 58.44% <100.00%> (+<0.01%) ⬆️

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.

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

codspeed Bot commented Oct 17, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 41.78%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 85 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ JBig2CCITTFaxImage.decode: JBIG2 MMR (bitmap-mmr.pdf) 1.2 ms 2.1 ms -41.78%

Tip

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


Comparing Snuffleupagus:Lexer-getString-skip-fromCharCode (50ab00d) with master (157d30e)

Open in CodSpeed

@Snuffleupagus
Snuffleupagus marked this pull request as ready for review October 18, 2026 08:54
@timvandermeij
timvandermeij merged commit f5cbdbc into mozilla:master Oct 18, 2026
31 of 32 checks passed
@timvandermeij

Copy link
Copy Markdown
Collaborator

Thank you for improving this logic!

This branch was previously deployed

1 inactive deployment
sync_pdfs — 50ab00d3 Deployed Oct 17, 2026 by Snuffleupagus via request #478
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.

3 participants