I had this issue when I first started using UE4, but it turned out my all-in-one PC was not up to it. I would wait ages for compilation.
Now I am using my Alienware desktop from 2014 and it has an i7 4th-gen quad core/8 threads and an AMD RX 480 graphics card. I put in an SSD as well. Glad to say, UE4 is running really fast.
Are you using VS 2019? I don’t recall making an changes in VS. I think (don’t quote me on this), the discrete graphics card helps a lot.
Like I said my all-in-one was slow as it used a low-end CPU with a GPU that only had 3 compute units!