electron: [Bug]: Windows Defender real-time protection causes slow boot for utility processes

Preflight Checklist

Electron Version

13.1.4

What operating system are you using?

Windows

Operating System Version

Windows 10 Version 21H1

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

The first file, referenced by index.html (loaded by main.js) loads as fast as the files after the first file or at least much faster.

Actual Behavior

The main.js loads a file index.html that itself references a style sheet and a JavaScript file:

function createWindow() {
    _mainWindow = new electron.BrowserWindow()
    _mainWindow.loadFile(path.join(__dirname, "index.html"))
    _mainWindow.on("closed", () => _mainWindow = null)
}

The style sheet that is referenced first takes around 1.7 seconds to load while following files take only like 1ms to load. The start up time of my Electron app is delayed by this 1.7s because of this. I don’t know where this delay comes from and how to fix this in the user code.

See the output of my test application:

$ npm start

> electron-performance-issue@1.0.0 start D:\electron-performance-issue
> electron .


Loading: file:///D:/electron-performance-issue/app/index.html (14 ms since last load)
Loading: file:///D:/electron-performance-issue/app/index.css (1775 ms since last load)
Loading: file:///D:/electron-performance-issue/app/index.js (0 ms since last load)

I considered using Webpack but

  • The electron-webpack-quick-start uses old dependencies and I didn’t manage it yet to get it running with current versions
  • I like to keep out this additional dependency and configuration effort

Testcase Gist URL

No response

Additional Information

I made a repository with the minimal code for this issue: https://github.com/c3er/electron-performance-issue

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 35 (8 by maintainers)

Commits related to this issue

Most upvoted comments

This could be related to Windows Defender’s real-time protection. I recently experienced slow startup and opened a question on StackOverflow (you can see it here). It turns out that disabling Windows Defender’s real-time protection gave me the expected startup speed.

The mysterious thing is, though, that other apps like VSCode open quite fast on my machine, even with Defender’s real-time protection enabled. Maybe it is possible to build your application in such a way that Defender doesn’t get in the way.

Btw, I setup a repo which prints timings to the console, which I found quite useful for debugging. Maybe it can be of use for people interested in investigating this issue.

Hey! Did u find a fix? Visual Studio Code, Discord, and Spotify have a very low startup time. Disabling Windows Defender’s real-time protection improves my app startup by up to 90%, It’s amazing! However, we cannot ask users to disable windows defender real-time protection or ask them to add the executable file to their excluded list.

Please Microsoft/Electron. Work on this. A whole suite of applications are impossible because of this. Anything that is meant to open a certain file and quickly displays/plays it (sound player, image viewer) would be really slow. I wonder if the “electron apps are slow” is a result of this issue. Because it electron really isn’t slow at all. If it wasn’t for the pesky start time.

@facuparedes That’s bad to hear. I think this issue should be reopened too. @nornagon

Hey @sibyl666, I couldnt find any workaround, so I’m living with this. I think this issue should be reopened.

Greetings!

This could be related to Windows Defender’s real-time protection. I recently experienced slow startup and opened a question on StackOverflow (you can see it here). It turns out that disabling Windows Defender’s real-time protection gave me the expected startup speed.

The mysterious thing is, though, that other apps like VSCode open quite fast on my machine, even with Defender’s real-time protection enabled. Maybe it is possible to build your application in such a way that Defender doesn’t get in the way.

Btw, I setup a repo which prints timings to the console, which I found quite useful for debugging. Maybe it can be of use for people interested in investigating this issue.

Would signing an Electron app actually prevent Defender from doing what ever it is doing to slow down the startup ? Would be nice if someone who has done that to confirm.