Sorry for the slow reply but I wanted to find some time to properly site down and collect the data, however, when I did yesterday I ended up spending the time on trying to figure out a solution instead. And I actually did find an alternative solution that resolves the issue completely for my system:
I upgraded my Windows 10 Home to Windows 10 Pro, and then switched to using Hyper-V instead of WSL 2, as also suggested by others earlier in this topic, this completely resolved the issue for me, the local environment is lightning fast now!
This might not be a solution for everyone but I’ll share what I did below, perhaps it will help at least some people with similar issues.
What I did is:
First I tried to resolve the issue in the existing Windows 10 Home + WSL 2 environment.
- I (once again) updated Docker to the latest version that just came out but this didn’t help at all.
- Experimented a bit with different resource allocations using “.wslconfig” but again this didn’t help at all.
- I then enabled the feature “Hypervisor Platform” in Windows 10. I’m not sure if it makes much sense from a technical point of view (I don’t know enough about it) but it did seem to improve the situation somewhat. That’s relatively speaking though as page load times were still between 5 an 10 seconds most of the time, and sometimes even more than 10 seconds.
Working in the Wordpress backend was equally slow, dramatic one should say better. Also, CPU usage and Power usage (checked in Task Manager) were very high while loading pages or working in the WP backend. A process called “COM Surrogate” usually would shoot up dramatically in CPU and Power usage and my laptop would get super hot and the fan was blowing like there is no tomorrow. I have no clue why as I was doing almost nothing in the test environment other than opening a few pages. I guess it’s somehow related to the combination of Windows 10 Home, Docker and WSL 2 and perhaps the way the files are shared between Windows and Docker in the DevKinsta setup as per the warning “Docker Desktop has detected that you shared a Windows file into a WSL 2 container, which may perform poorly.” that was mentioned previously in this topic already.
Then I switched to Hyper-V and it makes all the difference! The steps for that were/are:
- If you are on Windows 10 Home, upgrade to Windows 10 Pro. At least, I believe this is required as Windows 10 Home is not showing the “Hyper-V” and “Container” options in “Turn Windows features on or off”. I did the upgrade to Windows 10 Pro via de Microsoft store and the process is surprisingly simple and quick. It did cost 145 Euro… but for me that was better than wasting more time on a slow environment. The upgrade did initially say it failed, and the license was not activated, however, then I manually rebooted, and Windows then automatically finished the upgrade process anyway and after the reboot I was on Pro with the purchased Pro license active.
- After the upgrade I tested if the combination Windows 10 Pro + Docker + WSL 2 was any better but it wasn’t, the issue remained the same.
- After the above, it’s better to first export the mysql database(s) of the local development site(s). (I did it later but it’s easier to do it first to avoid having to switch back to WSL 2 later to get it)
- Then I enabled the “Hyper-V” and “Container” options in “Turn Windows features on or off”.
- Then in Docker in Settings > General, I disabled the “Use the WSL 2 based engine” option. And then clicked Apply & Restart.
- After that I started DevKinsta which will then attempt to create and update containers for the Hyper-V environment. I ran into an error during this process but the solution described here resolved that: Windows 10 Pro: DK0005 error (adding the path mentioned there as described)
- Once DevKinsta is up and running, import the mysql database(s) in the new environment.
After this my local environment is working very fast and is now a proper environment for development. The funny thing is that in Docker settings it says “WSL 2 provides better performance than the legacy Hyper-V backend.”, which I suppose is normally true but not in this case that is for sure!
All of the above is of course a workaround, it doesn’t solve the issue with WSL 2, but simply avoiding using it at all is good enough for me.