JW.
JW.

Reputation: 51668

Why is Electron app slow after inactivity?

I have an Electron app (running on a Mac) that waits in the background for a key press, before showing a window.

If I leave it in the background overnight and then use it, it will be very slow for the first 10 seconds or so. It seems like updating the DOM and inter-process communication are both slow. The delay isn't coming from my code, and it seems to affect the renderer process primarily. After the initial slowness, it starts working normally.

Is there any reason that an Electron app would do this? Is it getting unloaded from memory somehow?

What's odd is that the initial display of the window happens instantly; it's just after I start to do some inter-process communication that it slows down.

Upvotes: 1

Views: 748

Answers (1)

JW.
JW.

Reputation: 51668

There are a few possible answers to this, but after spending countless hours figuring it out, I thought I'd share the one that worked for me.

I was showing an animated SVG when I put the app in the foreground, and hiding it when I put it in the background. Apparently this was queueing up animation frames even while hidden, and then un-queueing them when it was shown, causing the delay.

It was fixed by upgrading Electron from 8.5.5 to 9.0.0, which I believe upgraded Chromium from 80.0.3987.165 to 83.0.4103.64. Not sure what the exact fix was, but it worked.

Upvotes: 0

Related Questions