How I reduced build time 7 times on Windows 10 dev PC

I am on Windows 10 Home PC (SSD) and I remembered that 2 years ago project build time was around 30 sec with --parallel.

I noticed that today everything-update build takes 3.5 min (without --parallel)!

Development cycle edit-build-test becomes cumbersome.

I dig into issues and most helpful was Temporary folder (/tmp) filled up with gradle_uploadXXXSHA1 files

So I disabled 8.3 file name support (elevated shell required, search for “cmd” in Start menu and hit Ctrl+Shift+Enter to get one):

fsutil.exe behavior query disable8dot3
fsutil.exe behavior set disable8dot3 1

This improved build time by 7%. I already had disable access time on NTFS:

fsutil.exe behavior query disable8dot3

you can disable via one of:

fsutil.exe behavior set disableLastAccess 1
fsutil.exe behavior set disableLastAccess 3

Next BIG thing is Windows Defender. Old tips to use procmon with MsMpEng.exe process name shown nothing. But MsMpEng.exe constantly takes 5-7% CPU and 300-500 KB/s IO during build.

The most important thing to consider is how Antivirus works. It injected itself into process address space and listen to OS events and inject itself into driver filters. So antivirus is invisible from Procmon!!

I collected paths that contains gradle from procmon and added base directories as exclude directories:

c:/home/devel (my project base dir)
c:/home/.gradle (my GRADLE_HOME)

https://support.microsoft.com/en-us/help/4028485/windows-10-add-an-exclusion-to-windows-security

One note. Gradle intensively uses TMP directory. I don’t want to exclude this directory from protection. So I added:

GRADLE_OPTS="$GRADLE_OPTS -Djava.io.tmpdir=c:/tmp"

This dropped build time 6 times (from more than 3 min to 30 sec).

I still saw 150KB/s IO. Remember that Antivirus injects itself into process! In my case it is java.exe which is also added for exclusion to Defender. This gives 0.1-0.2% CPU load and zero IO in Defender process!!!

Final result:

gradle --stop
gradle testCompile   # cold start
BUILD SUCCESSFUL in 1m 58s
gradle testCompile   # hot start, everything is UPDATED (before investigation was 3m 47s)
BUILD SUCCESSFUL in 28s

Next thing is to fight lots of deferred dependency resolutions that block actual fast re-compilation and resource processing.

5 Likes

I also excluded everything from Windows Search Indexing, forgot to mention as it was done year ago ))

If anyone hates GUI run in elevated cmd:

powershell -Command Add-MpPreference -ExclusionPath "C:\tmp"
powershell -Command Add-MpPreference -ExclusionProcess "java.exe"
powershell -Command Add-MpPreference -ExclusionExtension ".java"

That’s some serious detective work you’ve done to shave off those precious minutes from your build time. Nice one! The deep dive into the Temporary folder, disabling 8.3 file name support, and tackling Windows Defender are some pretty impressive moves.
The antivirus bit is super informative. Who would’ve thought it’d be such a sly fox, hiding from Procmon! Your GRADLE_OPTS solution is genius, and those gradle exclusion directories are a smart move.
Also, if you or any other Windows users are looking for a cheap Windows 10 key, there’s this old but gold Reddit sub for cheap Windows 10 keys. Might come in handy if you’re ever thinking of setting up another dev PC or something. Happy coding, mate!