Skip to content

Create shading patterns the size of the current path. (bug 1722807) #14230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2021

Conversation

brendandahl
Copy link
Contributor

Previously, when we created a shading pattern canvas we created it
as the same size as the page. This was good for caching if the same
pattern was used over and over again, but when lots of different
shadings are created that caused us to create many full page
canvases.

Instead of creating the full page canvses, instead create the canvas
as the same size as the current path bounding box. This reduces memory
consumption by a lot since most paths are pretty small. Also, in real world
PDFs it's rare for a shading (non shading fill) to be reused over and over again.
Bug 1721949 is an example where the same pattern is reused and it will be slightly
slower than before.

@brendandahl
Copy link
Contributor Author

brendandahl commented Nov 3, 2021

Some notes from performance testing:

  1. bug1722807_page2 is MUCH faster going from 62,066ms to 330ms in Firefox and the several GB memory increase is gone
  2. bug1721949 is a bit slower, but a pretty small difference

-- Grouped By pdf, stat, browser --

pdf stat browser Count Baseline(ms) Current(ms) +/- % Result(P<.05)
bug1721949 Overall chrome 50 136 168 32 23.27 slower
bug1721949 Overall firefox 50 175 185 10 5.87
bug1721949 Page Request chrome 50 2 2 0 4.82
bug1721949 Page Request firefox 50 2 2 0 -8.57
bug1721949 Rendering chrome 50 135 166 32 23.56 slower
bug1721949 Rendering firefox 50 172 183 10 6.06
bug1722807_page2 Overall chrome 5 868 308 -561 -64.56
bug1722807_page2 Overall firefox 5 62069 332 -61737 -99.47 faster
bug1722807_page2 Page Request chrome 5 6 4 -2 -27.59
bug1722807_page2 Page Request firefox 5 3 2 -1 -38.46
bug1722807_page2 Rendering chrome 5 863 303 -559 -64.83
bug1722807_page2 Rendering firefox 5 62066 330 -61736 -99.47 faster
issue13325_reduced Overall chrome 50 16 16 0 0.00
issue13325_reduced Overall firefox 50 24 11 -13 -54.85 faster
issue13325_reduced Page Request chrome 50 1 1 0 9.26
issue13325_reduced Page Request firefox 50 1 1 0 -37.04
issue13325_reduced Rendering chrome 50 15 15 0 -0.81
issue13325_reduced Rendering firefox 50 23 10 -13 -55.87 faster

@brendandahl
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Nov 3, 2021

From: Bot.io (Linux m4)


Received

Command cmd_test from @brendandahl received. Current queue size: 1

Live output at: http://54.241.84.105:8877/2bfc0cde59f7be6/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 3, 2021

From: Bot.io (Windows)


Received

Command cmd_test from @brendandahl received. Current queue size: 1

Live output at: http://54.193.163.58:8877/4fa737c913b1a67/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 3, 2021

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/2bfc0cde59f7be6/output.txt

Total script time: 23.11 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  errors: 3
  different ref/snapshot: 47
  different first/second rendering: 1

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

@pdfjsbot
Copy link

pdfjsbot commented Nov 3, 2021

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/4fa737c913b1a67/output.txt

Total script time: 34.45 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  errors: 643
  different ref/snapshot: 40
  different first/second rendering: 1

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

@brendandahl
Copy link
Contributor Author

Are these chrome annotation and form failures new? They seem to work fine locally in tests and in the viewer....

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Nov 4, 2021

Are these chrome annotation and form failures new?

I cannot recall having seen them before, unfortunately.
Also, note e.g. ShowText-ShadingPattern-page1 which is a regular eq-test without any annotations/forms.

They seem to work fine locally in tests and in the viewer....

When testing this patch in Google Chrome locally, I can reproduce the test-failures. However, there's no errors in the console that'd explain the rendering failures.

@brendandahl
Copy link
Contributor Author

I haven't fixed the annotation/form bug yet. Just pushing so I can try this out on linux/windows...

Comment on lines 96 to 99
const ownerBBox = owner.current.getClippedPathBoundingBox(
pathType,
ctx.mozCurrentTransform
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at the previous test-results, there's also a breaking error which I assume is caused by this line (since this method uses Util.intersect which can return null).

TEST-UNEXPECTED-FAIL | test failed issue6961 | in firefox | page1 round 1 | render : TypeError: can't access property 2, ownerBBox is null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, I totally missed that! It seems to fix the other issues. However, that PDF is now displaying wrong in a new way (it's wrong as is too). The computed bounding box for the shading is slightly too small. I'm not sure why yet. It's not going to be fun to debug, since that PDF has thousands of paths. :(

I still don't quite understand why breaking that PDF, breaks other PDFs. We shouldn't be reusing any canvases, but we must not be cleaning up something correctly when an error happens.

Copy link
Collaborator

@Snuffleupagus Snuffleupagus Nov 5, 2021

Choose a reason for hiding this comment

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

Could the problem be that we're actually re-using the same <canvas> for every page/document during tests, thus possibly keeping some bad graphics-state alive?

A while back I wanted to see if we could get rid of some intermittent failures by always creating a new <canvas> during tests, please see PR #12960; maybe we should see if that'd fixed these problems and potentially land that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That brings up a good point! The canvas state should be getting reset when we assign to the width/height in driver.js, but in chrome we add our polyfill for mozCurrentTransform and that does NOT get reset. That would explain why this was only an issue in chrome. I'm thinking we should either override the width/height attributes of the canvas to reset the transform stuff or manually wipe out the transform stack and reset the current transform. The former is probably less error prone since we wouldn't have to remember to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for the bounding box being wrong in issue6961, that is because of #14241.

Previously, when we created a shading pattern canvas we created it
as the same size as the page. This was good for caching if the same
pattern was used over and over again, but when lots of different
shadings are created that caused us to create many full page
canvases.

Instead of creating the full page canvses, create the canvas
as the same size as the current path bounding box. This reduces memory
consumption by a lot since most paths are pretty small. Also, in real world
PDFs it's rare for a shading (non shading fill) to be reused over and over again.
Bug 1721949 is an example where the same pattern is reused and it will be slightly
slower than before.
@brendandahl
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Received

Command cmd_test from @brendandahl received. Current queue size: 1

Live output at: http://54.241.84.105:8877/648f5c85255a8e3/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Windows)


Received

Command cmd_test from @brendandahl received. Current queue size: 2

Live output at: http://54.193.163.58:8877/4137d3fe75c1c05/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/648f5c85255a8e3/output.txt

Total script time: 21.10 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  errors: 675
  different ref/snapshot: 749
  different first/second rendering: 3

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

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/4137d3fe75c1c05/output.txt

Total script time: 41.97 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 27
  different first/second rendering: 1

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

@Snuffleupagus
Copy link
Collaborator

/botio browsertest

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/749ae76a4cf4950/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/39c04ff731af90b/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/39c04ff731af90b/output.txt

Total script time: 18.50 mins

  • Regression tests: FAILED
  errors: 635
  different ref/snapshot: 22

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

@Snuffleupagus
Copy link
Collaborator

/botio-linux browsertest

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Received

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

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

@Snuffleupagus
Copy link
Collaborator

/botio-linux browsertest

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Received

Command cmd_browsertest from @Snuffleupagus received. Current queue size: 1

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

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/749ae76a4cf4950/output.txt

Total script time: 37.61 mins

  • Regression tests: FAILED
  different ref/snapshot: 30

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

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Failed

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

Total script time: 18.58 mins

  • Regression tests: FAILED
  errors: 614
  different ref/snapshot: 20
  different first/second rendering: 2

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

@Snuffleupagus
Copy link
Collaborator

/botio-linux browsertest

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Received

Command cmd_browsertest from @Snuffleupagus received. Current queue size: 1

Live output at: http://54.241.84.105:8877/5fbcfe3d3546bce/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Failed

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

Total script time: 18.60 mins

  • Regression tests: FAILED
  errors: 614
  different ref/snapshot: 22
  different first/second rendering: 1

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

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/5fbcfe3d3546bce/output.txt

Total script time: 20.23 mins

  • Regression tests: FAILED
  different ref/snapshot: 28
  different first/second rendering: 1

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

Copy link
Collaborator

@Snuffleupagus Snuffleupagus 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, thank you!

@Snuffleupagus Snuffleupagus merged commit 38efd13 into mozilla:master Nov 6, 2021
@Snuffleupagus
Copy link
Collaborator

/botio makeref

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Windows)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 1

Live output at: http://54.193.163.58:8877/39fe3bab8910866/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Received

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

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

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Linux m4)


Success

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

Total script time: 20.87 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/39fe3bab8910866/output.txt

Total script time: 31.42 mins

  • Lint: Passed
  • Make references: FAILED

@Snuffleupagus
Copy link
Collaborator

/botio-windows makeref

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/330df8d5dadae8f/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Nov 6, 2021

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/330df8d5dadae8f/output.txt

Total script time: 38.22 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@timvandermeij
Copy link
Contributor

Awesome work on this and the other PRs; thank you!

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