Skip to content
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

Improves rendering performance of annotation layers. #5214

Merged

Conversation

CodingFabian
Copy link
Contributor

This change does the following:

  • Address TODO to remove getEmptyContainer helper.
  • Not set container bg-color. The old code is incorrect, causing it to
    not have any effect. It sets color to an array (item.color) rather
    css string. Also in most cases it would set it to black background
    which is incorrect.
  • only add border instructions when there is actually a border
  • reduce memory consumption by not creating new 3 element arrays for
    annotation colors. In fact according to spec, this would be incorrect,
    as the default should be "transparent".

Note that only Link annotations were actually setting a border style and
color. While Text annotations might have calculated a border they did
not color it. This behaviour is now controlled by the boolean flag.

@CodingFabian
Copy link
Contributor Author

I noticed this when looking at possible performance bottlenecks in #5207 - That PDF has many annotations, so this PR should help. Besides from making the dom lighter it also saves an 3 element array in all cases where no annotation color was set.

@timvandermeij
Copy link
Contributor

data.color at CodingFabian@4e6e51c#diff-18ca06e2bd5be4c9132b51f78388b8f0R87 will still be set to an array (because color is an array; see CodingFabian@4e6e51c#diff-18ca06e2bd5be4c9132b51f78388b8f0R84), and that is fine because it is converted to a CSS string over at https://github.com/mozilla/pdf.js/blob/master/src/display/annotation_helper.js#L69. So I'm not sure that the code is incorrect.

I should also mention that I almost have a PR ready for a complete rewrite of the annotation layer, and these issues are also resolved in that PR. I'll try to put it up tomorrow so we can see how we can go from there (I only have to combine the 50+ commits into two or three sensible ones). In that PR the Link annotation will be implemented (with even more support than we currently have for special borders etc.) and if we like the structure, we can easily extend it for other annotation types such as Text annotations.

@CodingFabian
Copy link
Contributor Author

cool,
but look at https://github.com/mozilla/pdf.js/blob/master/src/display/annotation_helper.js#L62
in line 62 you see: container.style.backgroundColor = item.color;
that will not work.

And with the array I save, I mean that in case color is not an array (to be precise not an array with 3 elements) then it will not just default to set it to [0, 0, 0] which would mean black color, but would default to transparent (I checked with the spec).

But I am happy to dump my changes and perhaps improve yours. The current code just does quite a lot of unnecessary work.

@CodingFabian
Copy link
Contributor Author

Oh, i also had planned a follow up PR. because as far as I see the annotationHighlight div is generated but never ever used (its hidden) the highlight is implemented with hover css. We should check that as well.

@CodingFabian
Copy link
Contributor Author

while this PR only aims at specific performance improvements, all of them are covered by #5218, great work @timvandermeij - depending on when #5218 will get merged we can merge or abandon this.
I prefer to improve the new implementation, but we should also see to not let it be WIP for too long.

@brendandahl brendandahl added this to the 2014 Q4 milestone Oct 23, 2014
@timvandermeij
Copy link
Contributor

@CodingFabian Could you rebase this PR? Let's try to land this first as my PR requires some more work and has to be rebased anyway.

@CodingFabian
Copy link
Contributor Author

sure, i didnt want to spend time if this makes your work more difficult. if you are ok with rebasing and landing, i will do that

@CodingFabian CodingFabian force-pushed the optimize-annotation-layer branch from 4e6e51c to 3c17063 Compare December 16, 2014 19:31
@CodingFabian
Copy link
Contributor Author

rebased.

@timvandermeij timvandermeij self-assigned this Dec 18, 2014
@timvandermeij
Copy link
Contributor

@CodingFabian Looks really good. One thing I have found: see #5218 (diff) and http://logs.glob.uno/?c=mozilla%23pdfjs&s=20+Aug+2014&e=20+Aug+2014#c23865 for reference. For that PR we did a lot of research and found that Adobe Reader defaults back to black if the C entry is missing. The spec only talks about the case where the array has 0 elements, but it does not say what to do if it's missing entirely. Otherwise we regress https://pdf.yt/d/XBjrpaYuieax9D6b (also compare that one to Adobe Reader to see that it falls back to a black border). Could you update that for this PR, i.e., make a distinction between the empty array and missing array case?

@CodingFabian
Copy link
Contributor Author

yes you are right. i did not update this pr because i thought we might abandon it or rebase it onto yours.

@CodingFabian CodingFabian force-pushed the optimize-annotation-layer branch from 3c17063 to d8b003e Compare December 19, 2014 23:12
@CodingFabian
Copy link
Contributor Author

thanks for bringing this up @timvandermeij - should be good now, right?

@timvandermeij
Copy link
Contributor

Yes, that's also what I had in mind. I'll go over it one more time tomorrow and then we can merge this. Thanks!

// colorspaces
data.color = color;
} else {
if (color === null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For https://pdf.yt/d/XBjrpaYuieax9D6b color yields undefined. Please change line 81 to var color = dict.get('C') || null; to fix this issue and check that this document renders correctly then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i made the null check a !color

This change does the following:
 * Address TODO to remove getEmptyContainer helper.
 * Not set container bg-color. The old code is incorrect, causing it to
   not have any effect. It sets color to an array (item.color) rather
   css string. Also in most cases it would set it to black background
   which is incorrect.
 * only add border instructions when there is actually a border
 * reduce memory consumption by not creating new 3 element arrays for
   annotation colors. In fact according to spec, this would be incorrect,
   as the default should be "transparent" for an empty array. Adobe
   Reader interprets a missing color array as black however.

Note that only Link annotations were actually setting a border style and
color. While Text annotations might have calculated a border they did
not color it. This behaviour is now controlled by the boolean flag.
@CodingFabian CodingFabian force-pushed the optimize-annotation-layer branch from d8b003e to 9796351 Compare December 20, 2014 21:50
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/567feedb80265f7/output.txt

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/d31a9d64e7c94d5/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/84f218e6c7263ab/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/84f218e6c7263ab/output.txt

Total script time: 17.33 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/d31a9d64e7c94d5/output.txt

Total script time: 23.26 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

timvandermeij added a commit that referenced this pull request Dec 21, 2014
Improves rendering performance of annotation layers.
@timvandermeij timvandermeij merged commit 6e994b1 into mozilla:master Dec 21, 2014
@timvandermeij
Copy link
Contributor

Thank you!

speedplane pushed a commit to speedplane/pdf.js that referenced this pull request Feb 24, 2015
…-layer

Improves rendering performance of annotation layers.
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