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

Make QueueOptimizer easier to read. #5008

Merged
merged 1 commit into from
Aug 5, 2014

Conversation

nnethercote
Copy link
Contributor

QueueOptimizer is really hard to read. Enough so that it's blocking my
efforts to streamline the representation used for operator lists.

This patch improves its readability in the following ways.

  • More descriptive variable names make the sequence checking much clearer,
    as do additional comments.
  • The addState() functions now return the index of the first op past the
    sequence, instead of setting context.currentOperation to the last op of
    the sequence.
  • The loop in optimize() is clearer.
  • The array modification in the fourth addState() function is much clearer
    -- we're just removing trios of ops.
  • All four |addState| functions are now more consistent with each other.

I used some debug printfs to find documents where these optimizations are
used and then checked that the number of optimized ops was the same before
and after my changes.

var i, ii = argsArray.length;
var state;
for (i = 0; i < ii; i++) {
var state = undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Travis complains about this:

src/core/evaluator.js: line 2577, col 11, It's not necessary to initialize 'state' to 'undefined'.

@nnethercote
Copy link
Contributor Author

I fixed the lint error.

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Failed

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

Total script time: 0.11 mins

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/7e792041d5197eb/output.txt

Total script time: 2.80 mins

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

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

@nnethercote
Copy link
Contributor Author

The test failures are all due to infrastructure problems, AFAICT.

@timvandermeij
Copy link
Contributor

@nnethercote Yes, they are. The bots will have to be kicked by @yurydelendik.

var iFirstPIIXO = curr - 1;

// Look for the quartets.
var i = iFirstSave + 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

would curr + 1 be better?

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 think iFirstSave + 4 is clearer. |curr| is really non-descriptive, which is why I move away from it and start using descriptive names immediately.

@CodingFabian
Copy link
Contributor

i gave a shot at reviewing this. It is quite exhausting to stay concentrated :) The new variables help. it is really hard to spot various +2 and its good that j+2 now has a better name.

There is still a lot of duplicate code, and I wonder if it could be somehow extracted. However the new code at least says a bit clearer what it does, thus making changes less risky.

I am not sure about the use of [i + 0] which is made to make it look nice and symmetrical.

As said, I think the code still does what it did before.


// At this point, i is the index of the first op past the last valid
// quartet.
var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
Copy link
Contributor

Choose a reason for hiding this comment

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

i like the >> 2 better, but i assume you want to make clear you deal with quartets right?

@Snuffleupagus
Copy link
Collaborator

Given that most, if not all, of this code was written by @yurydelendik, I think that it would be a good idea if he reviewed these changes.
@nnethercote Yury is currently on PTO, so I wanted to give you a heads-up that it might take a while before the reviewing is done.

@nnethercote
Copy link
Contributor Author

Thanks for the review. This code is tricky, so I agree that waiting for Yury to get back is wise. Do you know how long he's away for?

As for the remaining duplication... I feel that although the code for each addState() function is similar, it's not similar enough for there to be a factorisation that would improve the readability.

I'll address the remaining minor comments on Monday. Thanks for the review.

QueueOptimizer is really hard to read. Enough so that it's blocking my
efforts to streamline the representation used for operator lists.

This patch improves its readability in the following ways.

- More descriptive variable names make the sequence checking much clearer,
  as do additional comments.

- The addState() functions now return the index of the first op past the
  sequence, instead of setting context.currentOperation to the last op of
  the sequence.

- The loop in optimize() is clearer.

- The array modification in the fourth addState() function is much clearer
  -- we're just removing trios of ops.

- All four |addState| functions are now more consistent with each other.

I used some debug printfs to find documents where these optimizations are
used and then checked that the number of optimized ops was the same before
and after my changes.
@nnethercote
Copy link
Contributor Author

I converted the a[i + 0] instances to a[i].

@yurydelendik yurydelendik self-assigned this Jul 21, 2014
@nnethercote
Copy link
Contributor Author

@yurydelendik: any progress here?

@yurydelendik
Copy link
Contributor

I'll check this PR Monday

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Aug 4, 2014

From: Bot.io (Linux)


Received

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

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

@yurydelendik
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Aug 5, 2014

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/02d17b767397132/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Aug 5, 2014

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/aa94809ecc73472/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Aug 5, 2014

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/aa94809ecc73472/output.txt

Total script time: 19.79 mins

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

@pdfjsbot
Copy link

pdfjsbot commented Aug 5, 2014

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/02d17b767397132/output.txt

Total script time: 22.69 mins

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

yurydelendik added a commit that referenced this pull request Aug 5, 2014
Make QueueOptimizer easier to read.
@yurydelendik yurydelendik merged commit 2b87ff9 into mozilla:master Aug 5, 2014
@yurydelendik
Copy link
Contributor

Thank you

@nnethercote nnethercote deleted the better-QueueOpt branch August 6, 2014 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants