Check out a free preview of the full Electron, v3 course
The "Performance Considerations" Lesson is part of the full, Electron, v3 course featured in this preview video. Here's what you'd learn in this lesson:
Steve discusses performance considerations when combining web technologies with native desktop capabilities in Electron applications.
Transcript from the "Performance Considerations" Lesson
[00:00:00]
>> I did threaten midway through our time together, just to kinda like riff a little bit about performance, right? You are still on the hook for performance. And yes, the jokes about how Chrome is a memory hog. You are now Chrome, welcome, you are part of the problem.
[00:00:20]
That said, most of us use VS Code and don't complain, right? I would say most of us use Slack, and don't complain, but I don't know if that's true. But most of us, it is possible to have a performing app. The thing is that, yes, of course, Chromium is a dependency that is large, yes.
[00:00:40]
That said, depending on if you're doing this for work, right? Like, okay, also like, were you ever going to build a Linux app? Or both? Was your company gonna spin up teams bespoke to a Mac OS? You probably weren't, right? And so you have that, and it is not true that all Electron apps are memory hogs, or whatever.
[00:01:06]
Again, I don't think I've ever complained about the performance characteristics of VS Code, right? Maybe it's taking up a lot of memory right now, I don't know. But the fact of the matter is, the bigger thing is there's so much under your control, right? If you do things like write file sync, which in a world of promises, if you do that, I don't.
[00:01:24]
I don't know what to tell you, right? That's gonna lock the main thread. Yeah, your performance is gonna suffer. If you've ever watched any of those talks from Addy Osmani about the cost of JavaScript. Yeah, that JavaScript going over the wire is expensive. You know what is more expensive?
[00:01:41]
The time it takes to parse and compile that JavaScript to get an experience, right? If you don't use progressive loading, and all of the best practices in the browser and your electron app, it will be slow, cuz you got lazy, right? And so a lot of the performance truisms of progressively loading more code as you need it.
[00:02:01]
Which is why I think a lot of the bundlers and using Electron Forge makes sense, because the free things you get up like you, right? Dynamically loading things you know as you need to go. In all those cases, if you don't do those things, and you write sloppy JavaScript, you will have a slow app, and you don't get to blame Electron for that, right?
[00:02:20]
Yes, Chromium is a dependency, Chromium is large, but you also probably have 42 Chrome tabs open right now. You can still, for instance, one of the things that we would choose to optimize if we're gonna go all the way to the bottom of the apps that we built today, is that when we check to see if the file had changes on every input - debounce that, right?
[00:02:43]
Like little things like that, that are true. If you are doing it in the browser is true when you're building an Electron app, right? You don't just because there's no network, always, that does not mean that you cannot cause your own performance issues. And to keep those things in mind, and a lot of the best practices will get you most of the way there.
[00:03:04]
If you are doing things that are expensive, one, make sure they're asynchronous, but two, either that, or you have web workers available, right? And you have them reliably cuz you're not worried about different browsers. You have child processes in node that you can use. And in fact, you don't even need to use the child processes cuz you could spin up a renderer process, right?
[00:03:24]
That has no window, that it shows, that is a second thread that you could offload work to through that inter-process communication. And it's no different than anything that we saw before, right? You would just simply send stuff to it, and receive stuff in the same IPC that we saw earlier.
[00:03:39]
All those things are there, and you do have to leverage them, and make use of them. But there's nothing like inherently, there are enough, fast snappy mission-critical Electron apps out there that you don't get to blame Electron if your app is slow, right? And like all, but like there's not unique and special principles around Electron.
[00:04:01]
It is the same unique and special principles around web development, but also. Yeah, and you don't have to deal with the network, so it should be easier, right? And so just kind of, and if you do have to deal with a network, maybe storing stuff, and doing progressive loading, and a lot of the PWA techniques makes total sense.
[00:04:19]
And again, it is a much more reliable situation, except for the fact that if you write code that corrupts databases on somebody else's computer, it is a lot harder to fix. There is that kind of stuff as well.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops