Prosecutors do a lot of work, but the idea that they lose a lot is questionable. In the federal system, more than 90% of defendants plead guilty, and only around 1% of defendants take a case to trial and ultimately win. https://www.pewresearch.org/fact-tank/2019/06/11/only-2-of-f...
The numbers in state courts may vary, but in NY they are similar to the federal system. https://www.law.umich.edu/special/exoneration/Documents/New_...
Obviously a guilty plea still requires work, and maybe a lot of it. But in terms of outcomes, they rarely lose.