www.infoq.com
Desktop Applications in Electron: Pro Tips and Tricks
Excerpt
## Memory Usage Matters So one thing that's really important with Electron apps is that memory usage matters. We'll put it in big, big, big words. Electron gets, in my opinion, a little unfair rep about using too much memory. People get a little grumpy about it. They're like, “oh my, you know, A95.exe only used one MB of memory, and it did all this stuff. Why can't Electron apps in 2018 use that?” It's mostly nonsense, but they see a number and they get mad about it because of this. … So even though we've got this amazingly fast network and we can load all this stuff really fast, the flip side is that we really care about initial paint. And so anything that gets in the way- the libraries you load on startup will definitely get in the way of that. So it's also bad for memory usage because Node modules never get unloaded. So once you load them they're stuck. There are some clever hacks you can do to kick it out of memory, but those are taking over the Node module system. In general, libraries, once you load them, they're loaded. … ## Don’t Run Stuff in the Main Process Cool. So performance is cool, memory usage is cool. Another thing that I see a lot of new Electron developers, they're often coming from a web developer worlds. They're not used to native development. Chrome and Electron have this concept called the multi-process model, right? So your program in an Electron app starts off as a Node script, right? … How many people have ever used the remote module? It's really common enroll in Electron. The remote module is a way to access things on the main process from a render process. So it's really convenient. But the problem is it's also really slow because it has to use this synchronous send. It has to wait for a response. It stops the render process, asks the main process a question, gets back a response. And so if you do that once, it's not a big deal. If you do that by accident all the time, like from an on click callback or an on scroll callback, you're going to really grind.
Related Pain Points
Excessive memory consumption from loaded Node modules
7Node modules loaded at startup remain in memory and cannot be easily unloaded, causing cumulative memory bloat. Libraries loaded once are permanently resident, forcing developers to implement complex hacks to remove them from memory.
Main process blocking and slow inter-process communication via Remote module
7The Remote module uses synchronous messaging between renderer and main processes, causing the renderer to block while waiting for responses. Frequent calls (e.g., in click or scroll callbacks) significantly degrade performance.