Skip to content

Avoid branching in convertBlackAndWhiteToRGBA#20638

Merged
calixteman merged 1 commit intomozilla:masterfrom
calixteman:avoid_branching
Feb 8, 2026
Merged

Avoid branching in convertBlackAndWhiteToRGBA#20638
calixteman merged 1 commit intomozilla:masterfrom
calixteman:avoid_branching

Conversation

@calixteman
Copy link
Contributor

The function is now almost 8x faster than before.
And make the code in the file slightly more readable.

The function is now almost 8x faster than before.
And make the code in the file slightly more readable.
@calixteman
Copy link
Contributor Author

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/cc368382cf23509/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/82c7bed4e68d2f5/output.txt

Copy link
Contributor

@timvandermeij timvandermeij left a comment

Choose a reason for hiding this comment

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

r=me, with passing tests. Nice work!

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/cc368382cf23509/output.txt

Total script time: 42.07 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 2

Image differences available at: http://54.241.84.105:8877/cc368382cf23509/reftest-analyzer.html#web=eq.log

@calixteman
Copy link
Contributor Author

Our js jbig2 decoder is buggy with this file.
That being said, the "regression" is because of const elem = srcPos < srcLength ? src[srcPos] : 255; changed in to const elem = src[srcPos];. For sure the perf win of removing the branching in this expression is probably not that much but it'd a pity to have a penalty for something useless.

@timvandermeij
Copy link
Contributor

timvandermeij commented Feb 8, 2026

Given that the original rendering using the JS decoder was also incorrect, I don't really mind that this patch changes only this particular file (and none of the others) to a "different kind of incorrect" so to say, mostly because the WASM decoder handles it well and we try to use that as the default where possible anyway.

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/82c7bed4e68d2f5/output.txt

Total script time: 83.99 mins

  • Unit tests: FAILED
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 2

Image differences available at: http://54.193.163.58:8877/82c7bed4e68d2f5/reftest-analyzer.html#web=eq.log

@Snuffleupagus
Copy link
Collaborator

Our js jbig2 decoder is buggy with this file.

At the risk of asking stupid questions: Can the PDF.js JBIG2 decoder be replaced with a fallback JS one based on the PDFium decoder?
Looking at PR #19525 that was feasible for the compiled JPEG2000 decoder, so might it be possible for JBIG2 as well to reduce the amount of code that needs to be maintained here and improve rendering consistency?

@calixteman
Copy link
Contributor Author

Our js jbig2 decoder is buggy with this file.

At the risk of asking stupid questions: Can the PDF.js JBIG2 decoder be replaced with a fallback JS one based on the PDFium decoder? Looking at PR #19525 that was feasible for the compiled JPEG2000 decoder, so might it be possible for JBIG2 as well to reduce the amount of code that needs to be maintained here and improve rendering consistency?

No it isn't a stupid question.
I didn't make a js version of the decoder because I thought it'd be bigger but I didn't check. I'll check that, I'll let you know and we'll see. But for sure it'll make things more consistent.

@calixteman calixteman merged commit babd030 into mozilla:master Feb 8, 2026
11 checks passed
@calixteman
Copy link
Contributor Author

/botio makeref

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_makeref from @calixteman received. Current queue size: 2

Live output at: http://54.193.163.58:8877/7cdcce40dcee3e8/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/36fade69c44c3c8/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/36fade69c44c3c8/output.txt

Total script time: 18.61 mins

  • Make references: Passed
  • Check references: Passed

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