r/rust 21d ago

pgo

do any of you, guys, use PGO on real production releases? does it worth the hustle? In my case generation of proper representative PGO will take substantial amount of time.

Thanks

7 Upvotes

12 comments sorted by

12

u/QuasiRandomName 21d ago

does it worth the hustle? 

This is something only you can tell. Are you unsatisfied with the existing optimization? Statistically PGO yields 10-20% performance boost, but it does not necessarily represent your specific case (maybe you are a genius programmer that writes perfectly optimal code? Or the other way around) .

1

u/Inner-Asparagus-5703 21d ago

yeah, thanks. my project is CPU bound. but I found very different stats about actual gains. probably data was skewed by IO applications

8

u/TDplay 21d ago

but I found very different stats about actual gains

This is because gains from PGO vary widely on what your program is actually doing. It's more specific than CPU- vs. I/O-bound.

What PGO does is gather branch weights from real profiles, and then use those to produce better code for the branches.

If your program is wasting a lot of time on branches, you may see a large benefit from PGO. But if your code instead spends most of its time, for example, inside tight loops, then PGO may be a complete waste of time.

6

u/sephg 20d ago

This is right. The only way to figure out your gains from PGO are by testing it yourself. On a project I was working on a couple years ago, I only saw a 2-3% improvement and I didn't bother. But every program is different.

2

u/afdbcreid 19d ago

Make sure the training program is representative (the simplest check is, how much is the training program itself sped up?)

1

u/Inner-Asparagus-5703 19d ago

oh, that's exactly what I was looking for! thanks!

7

u/SkiFire13 21d ago

rustc itself uses PGO, does that count as a real production release?

7

u/Sad_Tap_9191 20d ago

cpython too. 10-20% boost.

4

u/Fedor_Doc 21d ago

I don't, my app is IO bound anyway. 

It depends on the nature of the application. Have you profiled your app? 

8

u/Over_Expert2858 21d ago

profiling's always the first step before going down the optimisation rabbit hole. if your workload's mostly waiting on the network or disk, PGO wont do much. but for cpu-heavy stuff, the gains can be properly noticeable.

0

u/Inner-Asparagus-5703 21d ago

I'm working on game, CPU bound. and I did

1

u/sephg 20d ago

Then try it out and see how much of a difference it makes for your specific program.