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 expensive for..in loops involving CMaps #5101

Merged
merged 2 commits into from
Aug 1, 2014

Conversation

nnethercote
Copy link
Contributor

This is much the same as #4804, which was abandoned.

},

contains: function(code) {
return code in this._map;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could avoid using the in operator here by changing this to:
return this._map[code] !== undefined;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's wrong with the in operator?

Copy link
Collaborator

Choose a reason for hiding this comment

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

According to micro-benchmarks, in is two orders of magnitude slower in modern browsers; see e.g. http://jsperf.com/in-vs-not-undefined.

This makes it easier for the representation to be improved.
This change avoids the element stringification caused by for..in for the
vast majority of CMaps.

When loading the PDF from issue mozilla#4580, this change reduces peak RSS from ~650
to ~600 MiB, and improves overall speed by ~20%, from 902 ms to 713 ms.  Other
CMap-heavy documents will also see improvements.
@nnethercote
Copy link
Contributor Author

I changed the in operators to undefined comparisons.

@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/8511673d5ea5388/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/809612b2f34f871/output.txt

@Snuffleupagus Snuffleupagus added this to the 2014 Q3 milestone Jul 30, 2014
@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/8511673d5ea5388/output.txt

Total script time: 21.09 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/809612b2f34f871/output.txt

Total script time: 23.14 mins

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

@Snuffleupagus
Copy link
Collaborator

/botio-linux lint

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/4257397abdcdd7d/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/4257397abdcdd7d/output.txt

Total script time: 0.78 mins

  • Lint: Passed

@nnethercote
Copy link
Contributor Author

The travis failure appears to be not my fault.

@nnethercote
Copy link
Contributor Author

I changed the in operators to undefined comparisons.

BTW, microbenchmarks are hard to write well. For example, the microbenchmark you mentioned measures normal (named) property accesses, but what's relevant for this code is array element accesses, and I've been told that Firefox is much faster on the latter case. See https://bugzilla.mozilla.org/show_bug.cgi?id=1046792 for more details.

yurydelendik added a commit that referenced this pull request Aug 1, 2014
Avoid expensive for..in loops involving CMaps
@yurydelendik yurydelendik merged commit ad2ea78 into mozilla:master Aug 1, 2014
@yurydelendik
Copy link
Contributor

Thank you for the patch

@nnethercote nnethercote deleted the CMap-forEach branch August 6, 2014 00:39
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.

4 participants