-
Notifications
You must be signed in to change notification settings - Fork 1.9k
xlsx: use TextDecoder and TextEncoder in browser #1486
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
Conversation
f4153d4
to
8eb2ccd
Compare
}); | ||
let content; | ||
// https://www.npmjs.com/package/process | ||
if (process.browser) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be if (!process.browser)
or am I misunderstanding the intention? process.browser
is truthy only in browser environments, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. I'll rebase and fix that.
8eb2ccd
to
99f48c3
Compare
Could you please run our benchmark on this branch vs master on node and post the numbers? Node also has |
Doing a profiling in chrome dev tools shows that the `Buffer.toString()` and `Buffer.from(string)` is using unexpected long cpu time. With the native TextDecoder and TextEncoder it can get much faster in browsers supporting it. On browsers not supporting TextDecoder, like Internet Explorer, this would fallback to original `Buffer.toString()` and `Buffer.from(string)`. This implements almost the same of exceljs#1458 in a non monkey-patching way covering xlsx only. Closes exceljs#1458 References: feross/buffer#268 feross/buffer#60 https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder
99f48c3
to
d29517c
Compare
Env: Windows 10 x64, node.js 12.18.4 LTS x64 npm run benchmark on master(834e893)
npm run benchmark on myfreeer:xlsx-text-browser(d29517c)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
Summary
Doing a profiling in chrome dev tools shows that the
Buffer.toString()
andBuffer.from(string)
is using unexpected long cpu time. With the native TextDecoder and TextEncoder it can get much faster in browsers supporting it.On browsers not supporting TextDecoder, like Internet Explorer, this would fallback to original
Buffer.toString()
andBuffer.from(string)
.This implements almost the same of #1458 in a non monkey-patching way covering xlsx only.
Closes #1458
References:
feross/buffer#268
feross/buffer#60
https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder
https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder
Test plan
Profiling below is based on reading
spec/integration/data/huge.xlsx
.Profiling result before this
Profile-before.json.gz
Profiling result after this
Profile-after.json.gz