NavMeshAgent Laggy in Final Build, but not in Editor

In my game, I am using NavMeshAgents for AI navigation. The agents navigate smoothly in the editor, but in my built version of the game they are laggy. I’ve also noticed that when I hover over the game’s icon on the Windows taskbar, the AI moves smoothly all of a sudden. How do I fix this so that they move smoothly all the time?