Skip to content

library initialization slowing down app start  #274

@SergeyRusskih

Description

@SergeyRusskih

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions