9

I'm not even sure what to call it. Whenever I launch a new application for the first time, it takes a few seconds to open. But then if I close and re-open the program it only takes a fraction of a second to open (basically how long I would expect it to take). This is the case until I reboot or replace the application file. This is particularly frustrating since I'm a programmer and I'm constantly compiling new builds and it's infuriating to wait 3-4 seconds just for my program to open. I never had this problem on Windows 10.

I'm guessing it some kind of caching behavior, but I can't figure out why it would make the program take 3 seconds to open. This is brand-new Windows 11 install on a brand-new laptop, fully up to date. I performed all of the system scans including sfc /scannow and they came back clean. Is there some way to remove/fix this behavior? Is this a bug in Windows 11? I'm not sure what else to try.

FWIW, the program I'm compiling is only ~150MB, statically linked. I have 32GB of RAM. The 3-4 second slow start up did not happen on Windows 10; it only took a fraction of a second to open there, every time.

Giacomo1968
  • 58,727

5 Answers5

16

This is in addition to @DrMoishe Pippik's answer.

Since you are compiling new binaries often, you are effectively showing your antivirus a lot of new programs that it has never seen before. this is in addition to other security mechanisms in place in modern windows, such as SmartScreen.

Several of these mechanisms will first try hash-based detection, which is already a time loss, and when that will come up as a completely unknown binary, will try a variety of other detection methods such as sandboxing and behavior analysis, which take up more time. Additionally, information about or even samples of the binary may be sent to the security solution's publisher, for further analysis and for tracking potential infections with new virus strands. Since this is done over the network, this may take a lot of time.

all of this may be done several times depending on the security tools active, leading to slow downs that are inevitable short of disabling the security measures keeping your machine safe.

Of course, once all of this has happened, the security solutions will be able to identify the binary has already been analyzed and cut their analysis short, which speeds up subsequent execution.

9

@DrMoishePippik hit many in his answer that I would have mentioned.. but .. I don't see the most important thing.

Cache Prefetching

I am guessing that this has to do with the windows prefetch cache more than anything else.

Prefetch files in Windows can significantly enhance your system’s performance.

This is normal behavior in Windows and most of us don't recognize it because it only happens once per application launch. It is even more evident when using an HDD.

In order to see your pre-fetched files, press the Windows+R button, type prefetch, hit enter.

While these files are beneficial, cleaning them occasionally can resolve performance issues and free up space.

If you clear this cache, you will find that every application will need to do this all over again one time on launch.

8

In all versions of Windows there may be an lag when first opening some applications for two main reasons:

In addition, it's possible that anti-malware scans a file the first time it is run during a session, or at least checks it's checksum. This scanning also slow Windows itself considerably, for some time, after booting or resuming from Hibernation. [N.B. However, Windows needs anti-malware; that OS should not be used without such protection!]

Once required resources are in memory, and once an interpreter has started, they are kept in RAM, and kept running, for some time, after an application has been closed. Therefore, subsequently running the app is far faster the second time than the first.

As an example, on this rather slow Windows 10 PC, OpenShot Video Editor took 70 seconds to run the first time, in this session, and 5 seconds to run after shutting the app and reopening it. That's 14 times faster the second time around!

How can you avoid that initial lag?

  • Include all resources inside the application. Do not use external DLL's, scripts or images that must be loaded at runtime.
  • Write in a language that produces compiled executables, such as C, C++, Delphi (Object Pascal). [For bonus points, write in assembly language, or, as I did for a Z80a, write the opcodes directly. ;-) ]
  • Never end your Windows session: use Sleep to keep the DLL's in RAM and runtime engines running.

Or: learn to appreciate that initial lag as time to meditate. [And, as a software developer, one is being paid while waiting for the app to start, so why worry?]

4

Windows 11 automatically scans any new executable for viruses. If you're building software on, say, Windows 11 Home Edition, then this can get to be a real drag.

It can be turned off temporarily via: Settings > Privacy & security > Windows Security > Virus & threat protection > Virus & threat protection settings: Manage settings > Real-time protection > Off.

Note this latter button says, "You can turn off this setting for a short time before it turns back on automatically." When I'm building programs, I need to switch this off to avoid the road bump on running each new build that the OP is talking about. Not sure exactly how long it lasts, but at least as long as any given sitting for me (I'd guess at least an hour or two).

In comments, Richard Tingle notes that this can be shut off permanently for specific folders, via a Windows Security exclusion.

4

You may want to consider setting up a Dev Drive.

Info from the Microsoft site:

Dev Drive builds on ReFS technology to employ targeted file system optimizations and provide more control over storage volume settings and security, including trust designation, antivirus configuration, and administrative control over what filters are attached.

As already mentioned by earlier posts, antivirus scans may be slowing things down and a Dev Drive has these scans disabled by default.