Skip to content

[Feature Request]: Compressed asar archives #29556

Closed

Description

@fabiospampinato

Preflight Checklist

Problem Description

  1. One problem that people have with Electron apps is that they are big.
  2. Another problem is that it takes a while until they are finished starting up, reading all the code, compiling and evaluating it takes a while.

Proposed Solution

To the best of my knowledge asar archives were introduced partially to improve on both of those problems, with much more emphasis on just being able to read files from disk faster, an obvious next step would be to gzip the files in the archive too, but I'm not sure if this has been discussed publicly, I couldn't find anything on that.

For the app I'm working on gzipping the archive brings its size down from ~11MB to ~4MB, which is a significant improvement, especially considering that it's not uncommon to see Electron apps which much larger asar archives, I wouldn't be surprised if the average was more like 50MB. Cutting this figure by 50~75% would be a significant step toward addressing issue number 1 which IMHO is already a compelling reason for implementing compressed asar archives.

Also regarding issue number 2 the faster files can be read from disk the faster the app can startup, if the asar archive is compressed there's just fundamentally much less stuff to read to begin with, so this should have a positive impact on issue number 2 too. Plus I'm not sure if this matters much, but the browser is kind of designed to work with gzipped files already, piping a gzipped file stream to the streaming parser might improve parse time even more.

Alternatives Considered

Forking Electron? This isn't really something that's reasonable for users to do, Electron should take care of this, ensuring also that many more Electron apps benefit from this kind of optimizations.

Additional Information

N/A.

Activity

  1. baconbrad commented on Jun 7, 2021

    @baconbrad
    Contributor

    The biggest complaint about the size isn't usually the ASAR but Electron itself. I noticed when ASARs are massive more often then not it is just bad dependency management so when they package their node_modules it is just a ton of unnecessary bloat. I have even seen people redundantly package the Electron module with their app.

    In my opinion making ASAR be a compression method is going to hurt the people it intended to help. As this would make ASAR less efficient at large file sizes if it had to also decompress during every execution. And if it was to add compression you might as well just use a pre-existing archive format since you are reinventing the wheel.

    If you have issues with large files needing to be included with your project I think this is better handled at the setup level. A lot of installer packages can compress the files meant for redistribution.

  2. MarshallOfSound commented on Jun 7, 2021

    @MarshallOfSound
    Member

    Compressing files in the ASAR archive will make reading files out of the archive noticeably slower, the main purpose of the ASAR is to (a) make file read perf better and (b) make delta updates easier. Adding compression makes both of these things worse.

    Compressing files adds an overhead to every file read, you can't seek to a random part of the file and read a contiguous stream of bytes because you'd have to read some kind of index / compression table (depending on the implementation) and on low end machines that de-compression would definitely be notice-able. Also what you refer to as:

    but the browser is kind of designed to work with gzipped files already, piping a gzipped file stream to the streaming parser might improve parse time even more.

    Even if it was accurate (which unfortunately it's not) would only apply to the renderer process, files have to be read out of the ASAR archive in both processes.

    Personally I'm a massive -1 on this being added to core

  3. fabiospampinato commented on Jun 7, 2021

    @fabiospampinato
    ContributorAuthor

    The biggest complaint about the size isn't usually the ASAR but Electron itself.

    Nobody outside of developers using Electron even know about that distinction, what matters to people is how big the binary is, purely from a size perspective it's irrelevant if we can squeeze X-MB out from Electron or from the asar archive, it's still X-MB.

    I noticed when ASARs are massive more often then not it is just bad dependency management so when they package their node_modules it is just a ton of unnecessary bloat. I have even seen people redundantly package the Electron module with their app.

    Sure, a lot of Electron apps just badly manage their dependencies, that argument is completely orthogonal though. For my specific use case I think my dependency tree is pretty shallow since I put a lot of work into that, and still by gzipping the thing one could squeeze ~7MB out of it, which is significant.

    A lot of installer packages can compress the files meant for redistribution.

    Obviously that's a good thing to do, which I'm already doing, but once the app is installed the asar archive is stored in a decompressed form anyway (at least under macOS).

    this would make ASAR less efficient at large file sizes if it had to also decompress during every execution.

    Compressing files in the ASAR archive will make reading files out of the archive noticeably slower

    I don't think that's actually true, even if we are assuming everybody has a top of the line M1 machine that can read ~2700MB/s, according to the benchmark here it looks like zstd can decompress stuff at ~2400MB/s, and lz4 can even go as high as ~4500MB/s, zstd has a streaming decompressor too (I assume lz4 does as well) so essentially decompressing stuff will be done in ~real-time.

    On the other end if somebody is reading files out of hard disks (which I guess are still pretty popular) the read speed could be easily cut by 10 times, while I think the decompression for a lower end machine won't be effected nearly as much.

    Basically given this rough reasoning it seems to me that worst case scenario reading+decompressing would be imperceptibly slower, while best case scenario (and actually average case scenario probably) reading+decompressing could be significantly faster, I'm not sure if perceptibly so though, one would need to measure it to be sure.

    All that while squeezing a significant number of megabytes out of the average Electron app (and even optimized ones like mine). Which is important, I'm not sure if we agree with that here, I'm not sure that this benefit is being weighted properly.

    Is there some flaw in my reasoning? Are the numbers totally inaccurate? Is there some kind of benchmark that we can make that could prove with hard numbers my or your expected performance?

    make delta updates easier

    Could you expand on that? I'm using electron-updater like most of other people I'd imagine, does that delta-updates the asar archives? Is that even possible considering that the bundles are supposed to be signed (at least under some platforms)?. Are you referring to some other tool?

    Also I don't understand what does it matter what the encoding of the files in the archive is, if the asar contains gzipped files the program could replace them with gzipped files just the same, adding support for this seems a very minor problem to me, or am I missing something?

    Even if it was accurate (which unfortunately it's not) would only apply to the renderer process, files have to be read out of the ASAR archive in both processes.

    I'll take your word for it since you know better on that. I don't think this matters in the end for this proposal since decompression can be done in ~real-time anyway.

  4. gpetrov commented on Jun 8, 2021

    @gpetrov

    Compressions has been requested before:

    #24470 (comment)

    I also don't understand why the core team is so much agains it.

    Streaming decompression on load is very common these days.

    Reading streaming, random access ASAR files should be just combined with node stream transformers so that any custom transforms can be applied- just like when creating ASAR files.

  5. dsanders11 commented on Jun 8, 2021

    @dsanders11
    Member

    For my specific use case I think my dependency tree is pretty shallow since I put a lot of work into that, and still by gzipping the thing one could squeeze ~7MB out of it, which is significant.

    I don't see how 7 MB is significant. It's disk space. Even in the world of mobile devices with 16 GB of disk space (which this isn't) that's 0.04% of available space. Disks in consumer computers are an order of magnitude or two bigger than that, making it even less significant. I just don't 50 MB or less of disk space being some big win in a world where drives are hundreds of gigabytes.

    I don't think there's much point in having a separate ASAR format if you add compression, at that point you're just creating yet another compressed archive format, so you might as well use a mature one.

    Sure, a lot of Electron apps just badly manage their dependencies, that argument is completely orthogonal though.

    It's not completely orthogonal. You're talking about adding complexity to Electron to shave megabytes off the on-disk size, when apps are already often wasting more than what would be saved just through lack of optimization. It doesn't make much sense to add more functionality and complexity to save 10 MB for developers if they're going to waste 20 MB by including files they could trim. It's not low-hanging fruit.

    Forking Electron? This isn't really something that's reasonable for users to do, Electron should take care of this, ensuring also that many more Electron apps benefit from this kind of optimizations.

    You don't need to fork Electron. ASAR support is layered in, not deeply rooted in the system. Electron is providing two pieces of functionality regarding ASAR: wrapping Node's fs to provide ASAR support in the main process, and providing support for requesting files in an ASAR from the renderer.

    If you want to use a compressed archive format, go ahead and use one. In the main process you can just use that archive format directly, or wrap fs if you want to make it seamless. For the renderer process you can intercept the file:// protocol and add support for reading out of an archive there, using interceptBufferProtocol or interceptStreamProtocol. You could use that to make .tar.gz archives work like how ASAR is currently supported.

    You could make a library which adds that functionality. That would be a good way to prove out real world benefits (could do head-to-head comparisons) and if it's a solution for a real problem the community has, it would see strong adoption.

    I also don't understand why the core team is so much agains it.

    I'm not on the core team and this is also a 👎 from me. It's added complexity (which will always bring bugs and edge cases) for minimal gain, and it can pretty much be done in user land. I'd much rather the energies of the maintainers be used in other features and maintenance.

  6. fabiospampinato commented on Jun 8, 2021

    @fabiospampinato
    ContributorAuthor

    I don't see how 7 MB is significant. It's disk space. Even in the world of mobile devices with 16 GB of disk space (which this isn't) that's 0.04% of available space. Disks in consumer computers are an order of magnitude or two bigger than that, making it even less significant. I just don't 50 MB or less of disk space being some big win in a world where drives are hundreds of gigabytes.

    I think there are a few issues with that reasoning:

    1. 7MB is a number I got for a fairly optimized/small app, compressing (with gzip) all the stuff that vscode ships with squeezes 70MB out of it, now at what point does the figure become significant in your eyes? To my eyes if a 1 megapixel image took 7MB on disk that would be really inefficient, still it would just be 7MB, I think it matters what those megabytes are being used for, I don't think Electron is already so efficient that it has the luxury to not care much about this.
    2. You are glossing over the potential performance improvements of this, I haven't heard an argument as to why reading 70% less stuff from disk and decompressing it in ~real-time shouldn't provide a performance improvement on average.
    3. You are glossing over how people perceive Electron apps, I agree with you that often a 100MB app is not that much of a problem on desktop compared to a 10MB app, but people perceive Electron apps are really bloated and heavy, people are developing Electron alternatives with the only advantage of producing smaller bundles left and right, it's in our interest to push back on this and ship smaller apps if we can.

    It's not completely orthogonal. You're talking about adding complexity to Electron to shave megabytes off the on-disk size, when apps are already often wasting more than what would be saved just through lack of optimization.

    It is completely orthogonal for the reasoning mentioned in a previous post, but to reiterate: I care a lot about bundle sizes and I keep my asar archive pretty lean, it's impossible for me to squeeze that to ~4MB without compression. You can't replace having compression with just switching to a more efficient dependency tree, even assuming both things took the same amount of effort to do.

    It doesn't make much sense to add more functionality and complexity to save 10 MB for developers if they're going to waste 20 MB by including files they could trim. It's not low-hanging fruit.

    I think it makes sense to add this small functionality and small complexity, if the complexity is indeed small, to reduce the size of asar archives by ~50~75%, as I said it's impossible for me to squeeze those 7MB out of my archive without compression, I went as far as developing my own filesystem watcher to have something smaller (and faster) than chokidar, I'm not just being lazy about this.

    And obviously one has to consider also that the effort required to to trim a dependency tree by 70% is many ordered of magnitude higher than the effort required to just compress everything, the two optimizations are completely orthogonal with each other.

    If you want to use a compressed archive format, go ahead and use one. In the main process you can just use that archive format directly, or wrap fs if you want to make it seamless. For the renderer process you can intercept the file:// protocol and add support for reading out of an archive there, using interceptBufferProtocol or interceptStreamProtocol. You could use that to make .tar.gz archives work like how ASAR is currently supported.

    You could make a library which adds that functionality. That would be a good way to prove out real world benefits (could do head-to-head comparisons) and if it's a solution for a real problem the community has, it would see strong adoption.

    That's a good point, I'd be happy to try to develop something like that in userland, especially if the maintainers can provide some target performance numbers that they would like this approach to hit in order to seriously consider implementing it in Electron itself.

    At the end of the day this optimization gets much less interesting if it benefits only one app (that's on the optimized-size already) rather than it benefitting potentially most Electron apps easily. As I said part of why this may be interesting is to push back on the idea that Electron apps are heavy, I can't really meaningfully push back on that just by updating my app, this should be something that Electron itself cares about.

    It's added complexity (which will always bring bugs and edge cases) for minimal gain, and it can pretty much be done in user land. I'd much rather the energies of the maintainers be used in other features and maintenance.

    If it makes sense for this to be implemented in userland IMHO it makes even more sense to implement it in Electron itself. At the end of the day every change can bring bugs and edge cases, that's not a good enough reason not to push Electron in the right direction.

    I suppose whether squeezing ~50~70% out of asar archives is a good enough reason is a matter of opinions though.

  7. fabiospampinato commented on Jun 8, 2021

    @fabiospampinato
    ContributorAuthor

    @vladimiry I couldn't help but notice that you seem to be against this proposal, since you maintain a fairly popular Electron app which ships a ~290MB asar archive that could be compressed down to ~64MB, squeezing ~226MB out of it, could you elaborate on why you are against this proposal exactly? (If you actually are)

  8. vladimiry commented on Jun 8, 2021

    @vladimiry

    you maintain a fairly popular Electron app which ships a ~290MB asar archive that could be compressed down to ~64MB, squeezing ~226MB out of it

    The asar size of ElectronMail has to be huge since anyway I have to bundle the static @ProtonMail web clients assembled for 3 different API endpoints (so 3 bundles of each web client). Besides that, I prefer not to compress the web resources for this project.

    I don't care much about asar size and its compression in the referenced project since:

    • I don't use auto-update (no delta updates matter), by design.
    • I don't have to serve the installation packages from my server, github does that (via /releases project's page). So redundant network traffic doesn't bother me much.
    • I'm not ready to trade app runtime performance for asar size. If I make the app to collect user computer performance statistics, and I face traffic limit, and I test compressed/uncompressed cases on different cpu/hdd/ssd setups, and I have free time/man-hours, then I could consider compressing the asar. But none of the named conditions are going to be met for the referenced project in the near future.
    • I have a huge backlog list for the project which I have not been catching up with lately. And also there is a list of unimplemented features. Both lists are mainly private. So, for me, the asar compression might potentially be an improvement, but with a very low priority.

    elaborate on why you are against this proposal exactly? (If you actually are)

    What I liked about @dsanders11 message is that it's practical. You get listed there a way you could jump into if you really want to store your assets in a smaller bundle.

    It's not like against but more like a very low priority thing, for my case. Of course it would be fine to get support for an opt-in compressed asar feature. But there are long-standing unresolved issues placed in https://github.com/electron/electron/issues/ which I believe are more important than this one. So my impression is that the bandwidth of the @electron team is already close to the limit (btw spectron support seems to get dropped soon). Another point is that compressed asar might make the UX of the end-user somewhat worse. No one cares about disk space these days but about startup time and general app performance. Of course, if you have to compete with other apps/services then asar size might potentially distinguish you from others.

    what matters to people is how big the binary is

    electron-builder supports the compression configuration value.

    but once the app is installed the asar archive is stored in a decompressed form anyway (at least under macOS).

    This looks somewhat contradictory to what you wrote earlier: what matters to people is how big the binary is (presuming you meant the installation package size).

  9. fabiospampinato commented on Jun 8, 2021

    @fabiospampinato
    ContributorAuthor

    @vladimiry Fair enough, thanks for your feedback on this 👍

    This looks somewhat contradictory to what you wrote earlier: what matters to people is how big the binary is (presuming you meant the installation package size).

    I meant to say that how big the app is is very important to some people, even if perhaps it shouldn't be as important. Meaning both the size of the installer is important (because that's the first thing that people see and most importantly it has to be downloaded) (and actually that could go down too by compressing the asar, in theory compressing that with zstd and then recompressing the whole thing with gzip or something should bring the size down a bit, but probably not by a significant amount), and the size of the app once installed.

  10. nornagon commented on Jun 16, 2021

    @nornagon
    Contributor

    I'm 👎 on this as mentioned elsewhere, for the following reasons:

    1. It's completely possible to implement this in userland. There's nothing particularly special about the asar format. If you care deeply about compressing your assets on disk, it's possible to go ahead and do that without the support of the Electron maintainers.
    2. It's not clear that disk usage is a major factor in adoption, ergonomics or usage of Electron or Electron apps, the occasional noisy user notwithstanding. The overwhelming majority of users do not notice or comment on the size of Electron apps on disk.
    3. Operating systems have some support for compressing files on disk already—NTFS, APFS and btrfs all have support for transparent compression. A user on a machine with restricted disk space or who cares especially about this sort of thing can configure this themselves, without any support from an app.
    4. Compressing the whole asar is not necessarily a good idea, especially when the asar can contain files that are already compressed, such as images or audio files. Further, storing a compressed asar on a compressed filesystem would mean double-decompression, which is a waste of CPU cycles for no benefit.
    5. Disk is cheap. At time of writing, around $0.10/GB. A saving of 150 MB is a saving of 1.5c.
    6. Network costs are a bit more relevant here, but compressing asar files would not impact transfer weight at all, because installers are already shipped in compressed containers.
    7. While some benchmarks show high decompression speeds in isolation, this is quite different from a benchmark of actual usage. In particular, asar files are accessed in random order, not sequentially. Additionally, it's important to consider that not all machines have highly capable CPUs—in fact, machines with restricted disk space are more likely to be also restricted in the availability of compute. It's far from clear that compressing asar files on disk would be a net performance gain in real-world usage.

    For these reasons, and given there is not interest from others in the maintainers group in implementing this feature, I'm closing this issue as status/wontfix.

  11. fabiospampinato commented on Jun 16, 2021

    @fabiospampinato
    ContributorAuthor

    It's completely possible to implement this in userland.

    That would only address the problem for ~one app, as I mentioned this gets a lot more interesting if the majority of Electron apps can benefit from this easily, I don't think it's likely that the majority of Electron apps are just going to reimplement this themselves or use some third-party library that does that.

    The overwhelming majority of users do not notice or comment on the size of Electron apps on disk.

    It might be interesting to poll people on this and get some actual numbers, I would bet that given the choice and a reasonable value proposition (i.e. smaller apps and not worse performance) both developers and users would want smaller apps.

    Operating systems have some support for compressing files on disk already—NTFS, APFS and btrfs all have support for transparent compression.

    That's an interesting possibility, but it's too obscure of a feature, people don't even know what NTFS or APFS are, "compress the whole partition yourself" is not a good alternative imo.

    Compressing the whole asar is not necessarily a good idea, especially when the asar can contain files that are already compressed, such as images or audio files

    Right, but the archiver could trivially be smart enough to adopt some hybrid strategy, compressing textual files but not images and other already-compressed stuff, e.g. does compressing this stuff deliver a 20%+ improvement? If not leave it uncompressed.

    Further, storing a compressed asar on a compressed filesystem would mean double-decompression, which is a waste of CPU cycles for no benefit.

    Right, I'd be surprised if >= 1% of people have enabled filesystem compression though, that sounds like a very very hypothetical issue to me.

    Disk is cheap. At time of writing, around $0.10/GB. A saving of 150 MB is a saving of 1.5c.

    That's the (optimistic) price for spinning rust which people shouldn't buy for their work computers to begin with, besides it's not possible to spend 10c to have one extra GB or something. Like you can't buy a square millimeter of a mansion for 1c or something, it's either the entire thing or nothing, nowadays depending on the computer you have you might even have to buy a new one to get a bigger disk, you can't even upgrade the disk.

    but compressing asar files would not impact transfer weight at all, because installers are already shipped in compressed containers.

    That's actually just false, obviously you can't keep compressing something indefinitely until you get to 1bit, but in practice compressing the same thing twice, especially if with two different algorithms, tends to deliver lower overall sizes.

    For example I have a ~123MB file containing a list of words that goes down to ~38MB with gzip -9, but it goes down to ~10MB with zstd -9 and then gzip -9.

    To provide another data point compressing Electron Mail's app.asar with gzip -9 delivers a ~63MB file, but a zstd -9 and gzip -9 delivers a ~48MB file.

    Just zstd-ing those files would deliver similar numbers, but importantly bundled Electron apps aren't compressed with zstd so there might (should?) be some improvements by compressing asar archives with zstd first, and running gzip over the zstd'd archive actually brings the numbers down a little bit more.

    Not all compression algorithms achieve the same results, otherwise there wouldn't be these many different ways to compress stuff.

    Additionally, it's important to consider that not all machines have highly capable CPUs—in fact, machines with restricted disk space are more likely to be also restricted in the availability of compute.

    Sure, but I don't think you need a super performant CPU to decompress stuff in ~real-time with zstd, like are there even computers available with top of the line SSDs but trash CPUs? If the disk is trash (HDD) I really don't think that the CPU would be nearly as garbage-y (there was a steep improvement from switching to HDDs to SSDs, there hasn't been a similarly significant steep improvement in CPUs in a while, unless I missed it).

    It's far from clear that compressing asar files on disk would be a net performance gain in real-world usage.

    I'd be happy to try to implement that and get some actual numbers, what are some actual numbers that you would like to see that would make you change your mind?

  12. baconbrad commented on Jun 17, 2021

    @baconbrad
    Contributor

    You are trying to solve a problem that doesn't really exist for computers in 2021. As @nornagon explained disk space is cheap. You shouldn't have issues finding a few hundred megs for an Electron app.

    As far as downloading goes Electron will likely be downloaded over a standard internet connection where data caps likely are not a concern. If there is a data cap it should barely scratch it. To put into context the average movie stream is around 2 GB and 500 MB for a half hour TV show. And these are at standard definition.

    Ideally I think everyone could agree if you can make it smaller that's great. But I think the majority consensus of the group agrees saving megabytes of data just does not seem like a good trade off for speed and performance which is the cost of any additional decompression.

  13. fabiospampinato commented on Jun 18, 2021

    @fabiospampinato
    ContributorAuthor

    As @nornagon explained disk space is cheap.

    Over big quantities spinning rust is cheap per GB, yes we all agree on that, but in practice let me know how I can add 1 extra GB to my computer for 10c, it just doesn't work like that you know.

    But I think the majority consensus of the group agrees saving megabytes of data just does not seem like a good trade off for speed and performance which is the cost of any additional decompression.

    Hypothetically obviously reducing size by 99.9999% for a decrease in startup performance of 0.00001% would be spectacular, it's not as clear cut as you put it, it's not always better to have an arbitrary bigger thing.

    And by the way that's not the argument I'm making with regards to performance, the argument I'm making is that on average it's probably more expensive to read a lot of stuff from disk than to read ~25-50% of that from disk and decompress it with some fast real-time streaming decompressor like zstd, so performance should improve somewhat on average, I think.

    I haven't yet heard anybody saying that they are willing to reconsider this if their performance expectations are proven wrong.

  14. vladimiry commented on Jun 18, 2021

    @vladimiry

    I still don't completely get why would a regular end user care about asar file size. The end users don't normally go that far, what they see is the installation package size which is a different topic. Again, I'm not against the feature request (btw once added feature might require the maintenance so extra burden), but I'd just prefer the more important actual issues/problems get resolved first, so from this point I understand why the issue got closed with won't fix status.

  15. fabiospampinato commented on Jun 18, 2021

    @fabiospampinato
    ContributorAuthor

    The end users don't normally go that far, what they see is the installation package size which is a different topic.

    It's not really a completely different topic, compressing the files in the asar with zstd should consistently and measurably lower installer sizes too, I provided some numbers about that in a post above.

    Maybe the argument here is that the whole installer should be compressed better rather than just the asar archive, but I don't think Electron has enough control over installer formats to switch to a better compressor, I'm not sure.

    I'd just prefer the more important actual issues/problems get resolved first

    Sure FWIW I agree with that, more important issues should be tackled first.

  16. VandeurenGlenn commented on May 21, 2022

    @VandeurenGlenn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions