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

Clean up duplicate string conversion functions #4512

Merged
merged 1 commit into from
Apr 2, 2014

Conversation

fkaelberer
Copy link
Contributor

This PR does the following:

  1. Move fonts.js->Font.string32 and fonts_loader.js->FontLoader.string32 to Utils.js->string32
  2. Move fonts.js->Font.stringToArray and fonts.js->CFFCompiler.stringToArray to Utils.js->stringToArray
  3. remove fonts.js->Font.arrayToString and use Utils.js->bytesToString instead
  4. Use String.fromCharCode(a, b) instead of String.fromCharCode(a) + String.fromCharCode(b)
  5. In Utils.js->bytesToString, use String.fromCharCode.apply(null, bytes) instead of pushing chars to an array if "possible" (because its >10x faster for longer arrays).
    If the bytes array is too long, a "too many arguments" warning will appear. Question: What is the maximum number of function arguments that is accepted by all browsers? FF/chrome/ie7 accept 500000/120000/120000 arguments, so I felt that a maximum of 65000 should be safe.

@fkaelberer
Copy link
Contributor Author

Another question: I kept fonts.js->Font.string16 where it is, because it is used only there. Which of the following is better?

  1. Keep it there, to avoid name space pollution and long 'globals' lists.
  2. Move it to Utils.js, to have string16 and string32 next to each other.

@fkaelberer fkaelberer closed this Mar 24, 2014
@fkaelberer fkaelberer reopened this Mar 24, 2014
@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/624613df320321e/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/fc679b2539ad6f8/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Failed

Full output at http://107.21.233.14:8877/624613df320321e/output.txt

Total script time: 24.81 mins

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

Image differences available at: http://107.21.233.14:8877/624613df320321e/reftest-analyzer.html#web=eq.log

@Snuffleupagus
Copy link
Collaborator

Something seems to be really wrong with Chrome on the Linux bot, let's investigate if this was caused by a Chrome update.

@fkaelberer
Copy link
Contributor Author

I'm afraid its my bad. Let me check this.

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

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

Total script time: 35.98 mins

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

@fkaelberer
Copy link
Contributor Author

Google Chrome throws "maximum call stack size exceeded" warnings, but only in the worker thread. In my tests with Chrome, the maximum byte array length in String.fromCharCode.apply(null, bytes) is 120000+ in the main thread, but only 60500 to 61000 in the worker thread.

Which brings us again to the question that I posed in the initial comment: what is the maximum safe size of the argument array?

@yurydelendik
Copy link
Contributor

Which brings us again to the question that I posed in the initial comment: what is the maximum safe size of the argument array?

Make it 8192

}
var strBuf = [];
for (var i = 0; i < length; ++i) {
strBuf.push(String.fromCharCode(bytes[i]));
Copy link
Contributor

Choose a reason for hiding this comment

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

for typed arrays you can do it in blocks by MAX_ARGUMENT_COUNT items. How many bytesToString calls are made with Array as argument (excluding simulated typed arrays)?

@fkaelberer
Copy link
Contributor Author

How many bytesToString calls are made with Array as argument

grep shows 9 lines of variable size arrays, but its hard to tell the characteristics of the input array from lines like font_loader.jsL294 var data = bytesToString(this.data) without deeper understanding of the code.

Because the whole patch did not affect overall performance, I refrained from doing any optimizations (e.g. chunking) which would complicate things.

@yurydelendik
Copy link
Contributor

Because the whole patch did not affect overall performance, I refrained from doing any optimizations (e.g. chunking) which would complicate things.

Not sure if it will complicate things though. However it shall stop arrays from from growing to the huge sizes -- it is already above MAX_ARGUMENT_COUNT as typed array and we are adding non-typed array of strings.

@fkaelberer
Copy link
Contributor Author

Not sure if it will complicate things though.

No, it did not, once I assured that only typed arrays are passed to bytesToString.

@timvandermeij
Copy link
Contributor

@fkaelberer Could you rebase this?

@yurydelendik
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Apr 2, 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/d2aa3fdf9bdcc81/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 2, 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/b6ce9360c1e8647/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 2, 2014

From: Bot.io (Windows)


Failed

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

Total script time: 2.45 mins

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

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

@yurydelendik
Copy link
Contributor

/botio-windows test

@pdfjsbot
Copy link

pdfjsbot commented Apr 2, 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/1b02b3da7627630/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 2, 2014

From: Bot.io (Linux)


Success

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

Total script time: 25.84 mins

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

@pdfjsbot
Copy link

pdfjsbot commented Apr 2, 2014

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/1b02b3da7627630/output.txt

Total script time: 22.29 mins

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

yurydelendik added a commit that referenced this pull request Apr 2, 2014
Clean up duplicate string conversion functions
@yurydelendik yurydelendik merged commit 20f6ded into mozilla:master Apr 2, 2014
@yurydelendik
Copy link
Contributor

Thank you for the patch

@fkaelberer fkaelberer deleted the cleanUpStringConversion branch April 2, 2014 13:05
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.

5 participants