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

Slightly improve the performance of removeNullCharacters #17165

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

calixteman
Copy link
Contributor

Most of the strings shouldn't contain special chars (<= 0x1F) so we can have a fast path which just checks if the string contains at least one such a char.

@calixteman
Copy link
Contributor Author

I profiled pdf.pdf with a sampling interval equals to 0.1ms.
Here's a profile without the patch:
https://share.firefox.dev/3Quo0Mb
and one with the patch:
https://share.firefox.dev/3tMyfCI
The function is now around ~3 times faster.

@Snuffleupagus
Copy link
Collaborator

It might not matter all that much, performance wise, but given how and where this helper function is being used do we still need the following part of it?

pdf.js/web/ui_utils.js

Lines 216 to 219 in f098121

if (typeof str !== "string") {
console.error(`The argument must be a string.`);
return str;
}

(This function was originally placed in src/shared/util.js, hence the additional validation.)

Most of the strings shouldn't contain special chars (<= 0x1F) so we can
have a fast path which just checks if the string contains at least one such
a char.
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.

r=me, thank you!

@calixteman
Copy link
Contributor Author

/botio integrationtest

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/8578b21c45edd38/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_integrationtest from @calixteman received. Current queue size: 1

Live output at: http://54.241.84.105:8877/8cc62fdc5c36313/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/8cc62fdc5c36313/output.txt

Total script time: 5.56 mins

  • Integration Tests: Passed

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/8578b21c45edd38/output.txt

Total script time: 18.78 mins

  • Integration Tests: FAILED

@calixteman calixteman merged commit f27f2bb into mozilla:master Oct 25, 2023
3 checks passed
@calixteman calixteman deleted the improve_removenullchars branch October 25, 2023 13:01
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.

None yet

3 participants