g.addTransform performance issues

Using g.addTransform to rotate some text.

firstTransform = juce::AffineTransform().rotated(juce::degreesToRadians(3.f), backgroundTextImagebounds.getCentreX(), backgroundTextImagebounds.getCentreY());

secondTransform = juce::AffineTransform().rotated(juce::degreesToRadians(-3.f), backgroundTextImagebounds.getCentreX(), backgroundTextImagebounds.getCentreY());

Then is the paint() method I do the following(twice)…
g.drawText(“sample text”);

And this is causing so much lag and I can’t see why. At first I thought maybe my code is broken and running the paint() method too much, but it really isn’t. I’m really confused. Any help?

Is that component being repeatedly repainted?

If so I’d recommend calling setBufferedToImage(true) on it - it’s almost always faster to cache a component’s graphics to an image and draw that each time it’s repainted than it is to draw text from scratch every time.

I’d also recommend using a profiler to actually see what’s taking a long time - it’s often surprising what the actual cause of poor performance is.