我花了几个小时玩 Electron,我观察到在屏幕上绘制一个简单的 html 文件始终需要超过 2.5 秒.时间线大致如下:
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
事件被触发;我们使用 new BrowserWindow()
ready
event is triggered; we create a window using new BrowserWindow()
我已经用我的代码建立了一个 存储库,该代码源自 Electron 的 快速开始 docs.
I have set up a repository with my code, which is derived from Electron's quick start docs.
关于我的机器,我在 2016 年的 ThinkPad T460 上运行 Windows 10,配备 SSD 和足够的内存.
Regarding my machine, I am running Windows 10 on a ThinkPad T460 from 2016 with a SSD and enough memory.
发送一个在启动时显示一个空白窗口的应用程序对我来说是不行的.我假设大多数开发 Electron 应用程序的人都有类似的想法.因此我的第一个问题是:我做错了什么吗?或者这是一个普通 Electron 应用程序的预期加载时间?
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
事件),所以不会显示空白窗口.这并不理想,因为这意味着用户不会得到任何关于应用程序实际加载的反馈.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.
Windows Defender 导致速度变慢,因此这不是 Electron 问题.
Windows Defender is causing the slowdown, so this is not an Electron problem.
事实证明,Windows Defender 实时保护导致启动持续时间比所需时间长得多.关闭实时保护后,我们获得了可以接受的性能:
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:
这意味着我提出的解决方案中的选项 1(显示启动屏幕)对于加载缓慢的应用应该非常有效.
This means that option 1 of my proposed solutions (showing a splash screen) should work quite well for slow-loading apps.
剩下的唯一事情就是弄清楚如何解决 Windows Defender 问题.为此,我提出了一个新问题.
The only thing left is to figure out how to solve the Windows Defender problem. For that purpose, I have asked a new question.
这篇关于处理缓慢的电子启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!