Repository: godot
Issue: Particles Constantly Causing Lag Spikes Under VERY Specific Circumstances
Labels: needs testing,topic:particles

<!-- Please search existing issues for potential duplicates before filing yours:
https://github.com/godotengine/godot/issues?q=is%3Aissue
-->

**Godot version:** 3.2.3.stable.official (Steam Release)
<!-- Specify commit hash if using non-official build. -->


**OS/device including version:**
Windows 10 Pro 19041.423
CPU: AMD FX-8350 4 GHz
GPU: GeForce GTX 1070 - 8 GB VRAM
RAM: 16 GB
Using an HDD, not SSD, for Storage
<!-- Specify GPU model, drivers, and the backend (GLES2, GLES3, Vulkan) if graphics-related. -->


**TL;DR Issue description:**
Instancing a particle system is causing lag spikes under specific combinations of window/fullscreen and vertical sync settings when using the Multi-Threaded Thread Model. This does not seem related to the shader caching issue that's been reported with particle systems previously.


**Issue description:**
I ran into a lag spike issue with particles in Godot which is NOT related to the one most people run into. Typically, the way lag spikes happen with particles is someone creates an instance of them and if the particles are not already properly loaded and cached, there's an initial lag spike, but then no more lag spikes following.

However, I was encountering lag spikes with EVERY particle system I instanced, even when the same one was already in the scene and running! First I had to trace the problem down to the particle system because it was a complex object causing the issues, once I did I tried everything I could think of to eliminate the lag spikes to no avail, even going so far as to create files and preload EVERY part of that particle system. Besides, once it was instanced, running and visible in the scene, creating new instances should not have caused more lag spikes.

Then just out of curiosity I tried running my game windowed instead of full screen and the lag spikes disappeared...

So... I  performed a LOT more testing to narrow this down and hit the following conclusions regarding instancing particle systems:
Full Screen Exclusive + No VSync = Fine
Full Screen Exclusive + VSync = Lag Spikes
Full Screen Exclusive + Compositor VSync = Lag Spikes
Full Screen Borderless + No VSync = Fine
Full Screen Borderless + VSync = Lag Spikes
Full Screen Borderless + Compositor VSync = Odd shearing, but otherwise Fine
Windowed + No VSync = Fine
Windowed + VSync = Lag Spikes
Windowed + Compositor VSync = Fine

And I was about to write this off as completely unsolvable for a vertical synced full screen... until I tried one more setting... as all of the above was done with the Thread Model set to Multi-Threaded...

Full Screen Exclusive + Compositor VSync + Single-Threaded Safe = Fine

And yeah, as you can tell, my system is one of the ones which has been hit hard by the Desktop Window Manager changes from Win10 Anniversary onward, so the new Compositor-based VSync option absolutely helped on my end, but it appears sticking with the Single-Threaded thread model is important too... at least, for now. I also understand that compositor-based VSync still has issues for some people so I plan to expose this setting as a user option once I get that far in my project.