vE5li / korangar

A next-gen Ragnarok Online client
MIT License
147 stars 33 forks source link

Make the profiler API sound. #86

Closed hasenbanck closed 2 months ago

hasenbanck commented 2 months ago

Before this change it was possible to trigger UB by calling start_measurement() of a profiler, before having called set_active() by calling start_frame().

The only real penalty right now is the check if the option is set, when calling the measurement functions. This shouldn't result in any measurable performance penalty, since this is an easy case for a branch predictor.

I removed the Pin, since it should not be possible using the external API and safe Rust to move the inner profiler around and thus invalidating the internal references.

I also moved the Box into the Profiler itself and documented the safety assumptions that must be upheld.