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

[api-minor] Simplify min/max computations in constructPath (bug 1135277) #14796

Merged
merged 1 commit into from
Apr 18, 2022

Conversation

calixteman
Copy link
Contributor

  • most of the time the current transform is a scaling one (modulo translation),
    hence it's possible to avoid to apply the transform on each bbox and then apply
    it a posteriori;
  • compute the bbox when it's possible in the worker.

@Snuffleupagus Snuffleupagus changed the title Simplify min/max computations in constructPath (bug 1135277) [api-minor] Simplify min/max computations in constructPath (bug 1135277) Apr 17, 2022
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.

Out of curiosity, what sort of improvement (e.g. in percent) did you see with this patch?

Comment on lines 1386 to 1387
// If the current matrix (when drawing) is a scaling one
// then min/max can easily be computed in using those values.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Grammar nits (assuming I'm understanding the code properly):

// If the current matrix (when drawing) has a scaling of one
// then min/max can easily be computed by using those values.

Comment on lines 1887 to 1891
Util.scaleMinMax(currentTransform, minMaxForBezier);
current.minX = Math.min(current.minX, minMaxForBezier[0]);
current.maxX = Math.max(current.maxX, minMaxForBezier[1]);
current.minY = Math.min(current.minY, minMaxForBezier[2]);
current.maxY = Math.max(current.maxY, [3]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This [3]-part looks like a simple typo, right?
If the patch passes all tests like this, then we'd probably want some better test-coverage here...


How about instead adding a new method for this code, rather than defining it inline like this?
Maybe something like the following (with perhaps a better name), placed e.g. somewhere around here:

updateScalingPathMinMax(transform, minMax) [
  Util.scaleMinMax(transform, minMax):
  this.minX = Math.min(this.minX, minMax[0]);
  this.maxX = Math.max(this.maxX, minMax[1]);
  this.minY = Math.min(this.minY, minMax[2]);
  this.maxY = Math.max(this.maxY, minMax[3]);
}

minMax[0] = Math.min(minMax[0], args[0]);
minMax[1] = Math.max(minMax[1], args[0]);
minMax[2] = Math.min(minMax[2], args[1]);
minMax[3] = Math.max(minMax[3], args[1]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a break; here as well, to prevent a possible future bug if this code is ever moved around.

Comment on lines 610 to 613
minMax[0] = Math.min(minMax[0], box[0], box[2]);
minMax[1] = Math.min(minMax[1], box[0], box[2]);
minMax[2] = Math.min(minMax[2], box[1], box[3]);
minMax[3] = Math.min(minMax[3], box[1], box[3]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are all of these lines actually supposed to use Math.min(...), or was there a bit too much copy-pasting happening here?

Comment on lines 724 to 726
// Apply a scaling matrix to some min/max values.
// If a scaling factor is negative then min and max must be
// swaped.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe place this comment just above the method instead?

@calixteman
Copy link
Contributor Author

Out of curiosity, what sort of improvement (e.g. in percent) did you see with this patch?

It isn't a crazy optimization, I just noticed that in different profiles it was the main bottleneck inside constructPath and thought that it shouldn't.
With the pdf in bug 1135277, ~1s was spent in updatePathMinMax in the main thread and with the patch ~20ms (and ~200ms extra time in the worker in buildPath).
In the different profiles I read in the last days, updatePathMinMax takes something around 3, 4%.

- most of the time the current transform is a scaling one (modulo translation),
  hence it's possible to avoid to apply the transform on each bbox and then apply
  it a posteriori;
- compute the bbox when it's possible in the worker.
@calixteman
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/0e9e9a6889c0224/output.txt

@pdfjsbot
Copy link

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/c4ea02a577d2911/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

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

Total script time: 23.49 mins

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

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

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/0e9e9a6889c0224/output.txt

Total script time: 24.45 mins

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

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

@Snuffleupagus Snuffleupagus merged commit f828792 into mozilla:master Apr 18, 2022
@Snuffleupagus Snuffleupagus linked an issue Apr 18, 2022 that may be closed by this pull request
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.

TilingType
3 participants