Profiler.BeginSample vs CustomSampler / Recorder APIs

I’m wondering what are the differences between these 2 concepts - Profiler.BeginSampler / EndSample and the newer CustomSampler API that allows creating new profiling labels.

Is CustomSampler going to replace BeginSample ? what are the typical uses for each of these?

It feels a bit like we already had this conversation but:
We’re moving things around under the hood to align the API mostly on ProfilerMarker and ProfilerRecorder. CustomSampler, Recorder and Profiler.BeginSample are very likely to get deprecated in this process over the next major unity releases.

BeginSmple already uses a static, special, ProfilerMarker under the hood that reports the name as it’s string metadata. The Profiler window then shows it as that metadata name. It’s not possible to record such samples using the Recorder APIs because they aren’t actually using their name as the sample name. It’s kind of the “easy way out” for impromptu additions of profiling scopes but also the one with the highest profiling overhead (as it sends the name to native, then as string metadata into the profiler stream, instead of just an ID like CustomSampler and ProfilerMarker would use). So it’s kinda like a debug log for temporary debugging. Generally speaking, you should stick with ProfilerMarker and ProfilerRecorder, which have lower overhead, more features, more upcoming features and future safety and are DOTS (or specifically Burst) compatible.

4 Likes

Thanks for the answer @MartinTilo !
Let’s discuss this again in a year from now LOL

2 Likes