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

SVG: optimize and refactor group creation code #7715

Merged
merged 3 commits into from
Oct 17, 2016

Conversation

timvandermeij
Copy link
Contributor

@timvandermeij timvandermeij commented Oct 12, 2016

This patch series brings down the number of transform groups for the Tracemonkey paper from 2790 to 1271, resulting in a much lighter DOM and faster rendering/scrolling. Refer to the commit messages for more information.

Copy link
Contributor

@yurydelendik yurydelendik left a comment

Choose a reason for hiding this comment

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

That is a really good start. I think we need to backout some changes in the viewer and avoid a regression in chrome.

var url = queryParams.file || '../../test/pdfs/liveprogramming.pdf';
var scale = +queryParams.scale || 1.5;
var DEFAULT_SCALE = 1.5;
var DEFAULT_URL = '../../web/compressed.tracemonkey-pldi-09.pdf';
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to have flexibility to change file via query string during testing different files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the new commits.

this.pgrp.appendChild(this.defs);
this.pgrp.appendChild(this.tgrp);
this.svg.appendChild(this.pgrp);
this.svg.setAttributeNS(null, 'transform', pm(viewport.transform));
Copy link
Contributor

Choose a reason for hiding this comment

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

this does not work for chrome -- we will need to create a root group and use it as this.svg ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the new commits.

/**
* @private
*/
_finishGroup: function SVGGraphics_finishGroup() {
Copy link
Contributor

Choose a reason for hiding this comment

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

_finishGroup can be removed, see yurydelendik@f4c8099

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the new commits. Nice find!

This patch:

- resolves a warning in the console about missing character encoding;
- makes the viewer use the same background color and PDF file as the
  regular viewer;
- simplifies the example to bring it more in line with the other
  examples.
This patch ensures that we only create transformation groups when it is
actually required and that we re-use transform groups as much as possible.
It reduces the number of transform groups for the Tracemonkey paper from
2790 to 1271, thereby making the DOM much lighter and rendering/scrolling
smoother. Moreover, it simplifies the code and prevents duplication.

Finally, we issue a warning when an unimplemented graphic state is
encountered. Before, this was ignored silently, making debugging harder.
Each well-formed SVG image has the following structure:

SVG element
- Definitions element
- Root group
  - Other group 1
  - ...
  - Other group n

This patch factors out initialization code into a private method in such
as way that the creation of this structure is clear from the code. The
root group is the replacement for the parent group from before. We need
this group as we cannot apply the viewport transform on the SVG element
itself (this caused issues in Chrome). If other code appends groups to
the SVG image, in reality it is appending those groups to the root
group, but this detail is abstracted away by this patch.
@timvandermeij timvandermeij changed the title SVG: group creation refactoring and optimizations SVG: optimize and refactor group creation code Oct 15, 2016
@timvandermeij
Copy link
Contributor Author

timvandermeij commented Oct 15, 2016

I have updated the commits based on the review comments. Could you check again?

Copy link
Contributor

@yurydelendik yurydelendik left a comment

Choose a reason for hiding this comment

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

Thank you for the patch.

@yurydelendik yurydelendik merged commit 273d2de into mozilla:master Oct 17, 2016
@timvandermeij timvandermeij deleted the svg-groups branch October 17, 2016 20:52
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
SVG: optimize and refactor group creation code
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.

2 participants