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

Avoid unnecessary array allocations in EvaluatorPreprocessor_read(). #5168

Merged

Conversation

nnethercote
Copy link
Contributor

EvaluatorPreprocessor_read() is called in two cases. For the normal
layer, the args array it produces is used beyond the bounds of the loop
in which EvaluatorPreprocessor_read() is called.

But for the text layer, the args array is used in a very short-term
fashion. This change reworks things so that a single array is repeatedly
used for the text layer. This reduces total JS allocations for the
Spoorkaart map by 11%, and has similar effects on many other PDFs.

@CodingFabian
Copy link
Contributor

looking at it, this feels a bit too magic for me. maybe this could be made a bit more explicit?
I do not know the code good enough to make a proposal though.

@nnethercote
Copy link
Contributor Author

I added nine lines of new comments explaining it. I'm not sure what else I can do to make it less magic.

// - |fn| is an outparam.
// - |args| is an inoutparam. This allows the caller to reuse a single
// array for all calls to this function (and there are many) if
// appropriate.
read: function EvaluatorPreprocessor_read(operation) {
// We use an array to represent args, except we use |null| to represent
Copy link
Contributor

Choose a reason for hiding this comment

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

does this comment still make sense?

@CodingFabian
Copy link
Contributor

I added a few inline comments which hopefully make it more clear why i think the behaviour is magic for me.

@Snuffleupagus
Copy link
Collaborator

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/2d05ab5e86b5803/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/6a9c4f06e25c2e4/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/2d05ab5e86b5803/output.txt

Total script time: 2.83 mins

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

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/6a9c4f06e25c2e4/output.txt

Total script time: 22.27 mins

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

@Snuffleupagus
Copy link
Collaborator

/botio-windows test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/92fd7e5389f2dca/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/92fd7e5389f2dca/output.txt

Total script time: 19.78 mins

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

EvaluatorPreprocessor_read() is called in two cases. For the normal
layer, the args array it produces is used beyond the bounds of the loop
in which EvaluatorPreprocessor_read() is called.

But for the text layer, the args array is used in a very short-term
fashion. This change reworks things so that a single array is repeatedly
used for the text layer. This reduces total JS allocations for the
Spoorkaart map by 11%, and has similar effects on many other PDFs.
@nnethercote
Copy link
Contributor Author

I've expanded the comments. I think the comment above EvaluatorPreprocessor_read() is now the largest single comment in the entire codebase.

@CodingFabian
Copy link
Contributor

I like it better now

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

@Snuffleupagus
Copy link
Collaborator

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

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

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/12c0f2e2d22f5ab/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/12c0f2e2d22f5ab/output.txt

Total script time: 19.95 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/d922c1fb619374a/output.txt

Total script time: 22.35 mins

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

Snuffleupagus added a commit that referenced this pull request Aug 15, 2014
Avoid unnecessary array allocations in EvaluatorPreprocessor_read().
@Snuffleupagus Snuffleupagus merged commit 9b480d7 into mozilla:master Aug 15, 2014
@Snuffleupagus
Copy link
Collaborator

Thanks for the patch!

@nnethercote nnethercote deleted the EvaluatorPreprocessor_read branch August 15, 2014 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants