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

library initialization slowing down app start #274

Open
SergeyRusskih opened this issue Mar 24, 2023 · 0 comments
Open

library initialization slowing down app start #274

SergeyRusskih opened this issue Mar 24, 2023 · 0 comments

Comments

@SergeyRusskih
Copy link

SergeyRusskih commented Mar 24, 2023

I'm developing a web application that has to maintain very low cold start latency and is running on slow devices. After importing the pako library I've noticed a 10% increase in the parsing & execution time of the startup JS module. I've noticed that the library does initialization right after its files are loaded. After some investigation, I noticed that removing that lines of code solves the latency issue. I confirmed that no functions that use that array are called. I also excluded all other library files.

const _utf8len = new Uint8Array(256);
for (let q = 0; q < 256; q++) {
  _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1);
}

That piece of code is very fast to execute as part of an independent benchmark but slows down overall execution. The benchmarks don't take into account the initialization code. In older browsers, allocating Uint8Arrays of any size can either trigger a GC sweep or block a network thread (ArrayBuffers used to be allocated from the network heap).

Is it possible to introduce the option to pay the library initialization cost once we need it instead of doing everything upfront? This would also allow you to benchmark the overhead that is now hidden.

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

No branches or pull requests

1 participant