Repository navigation
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem Description
- One problem that people have with Electron apps is that they are big.
- 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
baconbrad commentedon Jun 7, 2021
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.
MarshallOfSound commentedon Jun 7, 2021
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:
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
fabiospampinato commentedon Jun 7, 2021
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.
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.
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).
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?
Could you expand on that? I'm using
electron-updaterlike 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?
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.
gpetrov commentedon Jun 8, 2021
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.
dsanders11 commentedon Jun 8, 2021
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.
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.
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
fsto 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
fsif you want to make it seamless. For the renderer process you can intercept thefile://protocol and add support for reading out of an archive there, usinginterceptBufferProtocolorinterceptStreamProtocol. You could use that to make.tar.gzarchives 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'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.
fabiospampinato commentedon Jun 8, 2021
I think there are a few issues with that reasoning:
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.
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.
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.
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.
fabiospampinato commentedon Jun 8, 2021
@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)
vladimiry commentedon Jun 8, 2021
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:
/releasesproject's page). So redundant network traffic doesn't bother me much.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
spectronsupport 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.electron-buildersupports thecompressionconfiguration value.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).fabiospampinato commentedon Jun 8, 2021
@vladimiry Fair enough, thanks for your feedback on this 👍
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.
nornagon commentedon Jun 16, 2021
I'm 👎 on this as mentioned elsewhere, for the following reasons:
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.
fabiospampinato commentedon Jun 16, 2021
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.
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.
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.
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.
Right, I'd be surprised if >= 1% of people have enabled filesystem compression though, that sounds like a very very hypothetical issue to me.
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.
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 withzstd -9and thengzip -9.To provide another data point compressing Electron Mail's
app.asarwithgzip -9delivers a ~63MB file, but azstd -9andgzip -9delivers 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.
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).
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?
baconbrad commentedon Jun 17, 2021
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.
fabiospampinato commentedon Jun 18, 2021
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.
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.
vladimiry commentedon Jun 18, 2021
I still don't completely get why would a regular end user care about
asarfile 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.fabiospampinato commentedon Jun 18, 2021
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.
Sure FWIW I agree with that, more important issues should be tackled first.
VandeurenGlenn commentedon May 21, 2022