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

Optimize utf8 decoder #28220

Closed
wants to merge 3 commits into from
Closed

Optimize utf8 decoder #28220

wants to merge 3 commits into from

Conversation

ycw
Copy link
Contributor

@ycw ycw commented Apr 25, 2024

This PR attempts to boost perf for loaders which need decoding utf8 from an uint8array;

The implementation aligns to new TextDecoder('utf-8', { fatal: false }) meaning that malformed data will be substituted with replacement character.

Benchmark: https://jsperf.app/genija/2
in Edge 124.0.0.0 / Windows, it outperforms the old approach #12933 and TextDecoder both by ~90%

Tests: https://jsfiddle.net/sa37f1qh/

Copy link

github-actions bot commented Apr 25, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
674.4 kB (167.1 kB) 675.3 kB (167.3 kB) +841 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
453.8 kB (109.6 kB) 453.8 kB (109.6 kB) +0 B

@ycw ycw changed the title Implement Uint8Array to UTF8 in JS Optimize utf8 decoder Apr 26, 2024
@Mugen87
Copy link
Collaborator

Mugen87 commented May 4, 2024

TBH, I'm not a fan of such implementations when there is a standard API that can be used. I understand there is a performance boost but the new code is also hard to maintain and read. And there are currently no complains about too slow parsing times in context of decodeText().

I would prefer to actually remove the entire TextDecoder fallback in decodeText() and always rely on this class since it should be supported in all common browsers and node. If a project reports compatibility issues, it has to add add a TextDecoder polyfill.

@ycw
Copy link
Contributor Author

ycw commented May 4, 2024

I would prefer to actually remove the entire TextDecoder fallback in decodeText()

done. #28278


closed. Reason: hard to maintain

@ycw ycw closed this May 4, 2024
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.

None yet

2 participants