Answer a question

I'm developing an electron application and the thing I don't understand is how apps like visual studio code achieve so fast startup times, by that I mean the time between clicking the icon until a window opens (until main.js gets loaded).

I already read many articles about speeding up electron but they all just talk about the stuff that happens AFTER main.js is loaded.

I downloaded the electron-quick-start example and packaged it using electron-builder as portable app.

  • Visual Studio Code: 1-2 secs until a window shows up
  • electron-quick-start: 5-10 secs

I was just wondering where the performance issue is, portable? electron-builder?

I found an issue in electron-builder that seems to indicate, that portable apps are extracted into a temp folder on app start, thats whats slow

Answers

Just to close this question:

Problem:

As indicated in the comments, the problem really is the portable mode of electron-builder. Portable Apps first unpack themselves into a temporary folder on your computer which can be a cpu intensive task because of compression.

Only after the app files have been unpacked, the main.js is actually loaded by node / electron.

Solutions:

Use an installer

When using an installer, the unpacking is done during installation of course, and not every time the app is started.

Use a splashimage (untested)

Although it is nowhere mentioned in the electron-builder docs, the code seems to indicate that you can set a splashImage bmp option:

https://github.com/electron-userland/electron-builder/blob/master/packages/app-builder-lib/src/targets/nsis/nsisOptions.ts

/**
 * The image to show while the portable executable is extracting. This image must be a bitmap (`.bmp`) image.
 */
readonly splashImage?: string | null

That would at least make it clear something is happening, instead of the user clicking the icon multiple times because the app doesn't open

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐