Quater sine wave

It looks like your starting point is a 50Hz sine wave and you appear to be using this to generate a SPWM signal with a frequency of 25kHz. But what requirements are there, if any, about the resolution of the duty cycle ( say can it be +/- 5% ) and are there any requirments about its phase alignment. Clearly the timer frequency must be a quite high multiple of the SPWM frequency if you want a reasonable duty cycle resolution.

I guess that you have started with a picture like this and are implementing a solution based on those principles. However, there could be a simpler solution as others have suggested by just having a duty cycle look up table indexed by the period into the 50Hz cycle. Instead of the duty cycle, the table could even hold just the "on" period of the PWM pulse (at 25kHz, a 50% duty cycle for example has an "on" period of 20us).

from: Sinusoidal Pulse Width Modulation - an overview | ScienceDirect Topics

Since you are prepared to hold the table in RAM, it would be better to build it dynamically in setup() instead of hard coding it. That would allow you use the "heavy" functions such as sin() because it is not time critical and parameterise things like the sine wave frequency and the duty cycle frequency. It becomes more complicated if you want to hold the table in program (flash) memory.