I have spent some hours playing with Electron and I have observed that it consistently takes more than 2.5 seconds to draw a trivial html file to the screen. The timeline is roughly as follows:
ready
event is triggered; we create a window using new BrowserWindow()
I have set up a repository with my code, which is derived from Electron's quick start docs.
Regarding my machine, I am running Windows 10 on a ThinkPad T460 from 2016 with a SSD and enough memory.
Shipping an application that shows a blank window for so long upon startup is a no-go for me. I assume most people developing Electron apps think similarly. Hence my first question: am I doing something wrong? Or is this the expected loading time for a trivial Electron app?
Assuming this is normal behavior, what is the common way to deal with this problem? Some ideas come to mind:
ready-to-show
event), so no blank window is shown. This isn't ideal, since it means that the user doesn't get any feedback whatsoever that the application is actually loading.Given this must be a common problem, I hope standard solutions have been found by the community. I'd be glad if someone can point me in the right direction.
It is just the renderer, and just like a web app in a regular browser, it uses HTML, CSS and JavaScript to build an interface and provide functionality. Those are a lot of extra layers. And because of this additional abstraction, it can be slower than a finely tuned native app.
Electron will use a ton of memory because it's running a full browser inside a browser/desktop, Chromium, along with running v8 and all of it's own code. Along with that Chromium is already known for high memory usage. So it's relatively normal to see high memory.
Electron's number one strength is its turnaround speed. No other application development framework can go from 0 to fully functioning app as quickly as Electron can. Recently we were able to turnaround an app for a client in 2 weeks, because it was built on top of an existing React library.
Windows Defender is causing the slowdown, so this is not an Electron problem.
It turns out that Windows Defender real-time protection causes startup to last much longer than needed. After turning real-time protection off, we achieved acceptable performance:
This means that option 1 of my proposed solutions (showing a splash screen) should work quite well for slow-loading apps.
The only thing left is to figure out how to solve the Windows Defender problem. For that purpose, I have asked a new question.
What if you hid your window until it's ready to show, then show your window, and while your window's hidden show a loading spinner.
First only show your main window until after it's ready:
var mainWindow = new BrowserWindow({
show: false
});
mainWindow.webContents.once('did-finish-load', function ()
{
mainWindow.show();
loadingWindow.close();
});
Meanwhile show a loading spinner:
var loadingWindow = new BrowserWindow({
width: 200,
height: 200,
transparent: (process.platform != 'linux'), // Transparency doesn't work on Linux.
resizable: false,
frame: false,
alwaysOnTop: true,
hasShadow: false,
title: "Loading..."
});
loadingWindow.loadURL('file://' + __dirname + '/loadingAnimation.gif');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With