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

Use a more performant utf8 decoder algorithm. #3204

Merged
merged 1 commit into from
Oct 26, 2019

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Oct 26, 2019

Fixes #3163

Fixes denoland#3163

Co-authored-by: Kitson Kelly <me@kitsonkelly.com>
Co-authored-by: Qwerasd <qwerasd205@users.noreply.github.com>
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM -

Eagerly watching for perf changes to text_decoder on https://deno.land/benchmarks#exec-time

@ry ry merged commit c5fe657 into denoland:master Oct 26, 2019
@ry
Copy link
Member

ry commented Oct 26, 2019

Improved execution time from 1.9s to 0.1s. Nice!

sbgvbvq9

12,12,12,12,12,12,12,24,12,12,12,12, 12,24,12,12,12,12,12,12,12,24,12,12,
12,12,12,12,12,12,12,36,12,36,12,12, 12,36,12,12,12,12,12,36,12,36,12,12,
12,36,12,12,12,12,12,12,12,12,12,12
][state + type];

Choose a reason for hiding this comment

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

Can't we gain even more perf by creating those long arrays outside of the function ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we gain even more perf by creating those long arrays outside of the function ?

Seems like v8 optimizes it. I wrote this decode function, and in my testing I got more performance by inlining the arrays than by having them as consts defined outside of the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, V8 optimises things like this, not sure why it is more performant this way, but likely because V8 can understand 100% that there are no mutations to this arrays because they exist in a function that is 100% knowable. In another scope, they might limit the analysis of potential mutations. They aren't like strings and the string table, and where const means const.

Choose a reason for hiding this comment

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

really good to know thanks !

@kitsonk kitsonk deleted the text_decoder_perf branch August 2, 2022 04:45
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.

Text decoding performance abysmally slow.
4 participants