Using C++ profilers

To optimize Godot's performance, you need to know what to optimize first. To this end, profilers are useful tools.

Note

There is a built-in GDScript profiler in the editor, but using C++ profiler may be useful in cases where the GDScript profiler is not accurate enough or is missing information due to bugs in the profiler.

Setting up Godot

To get useful profiling information, it is absolutely required to use a Godot build that includes debugging symbols. Official binaries do not include debugging symbols, since these would make the download size significantly larger.

To get profiling data that best matches the production environment, you should compile binaries with the following SCons options:

  • For editor binaries: target=editor use_lto=yes

  • For debug export templates: target=template_debug use_lto=yes

  • For release export templates: target=template_release debug_symbols=yes

    • debug_symbols=yes is required as export templates are stripped from debugging symbols by default.

It is possible to run a profiler on less optimized builds (e.g. target=template_debug without LTO), but results will naturally be less representative of real world conditions.

Warning

Do not strip debugging symbols on the binaries using the strip command after compiling the binaries. Otherwise, you will no longer get useful profiling information when running a profiler.

Benchmarking startup/shutdown times

If you're looking into optimizing Godot's startup/shutdown performance, you can tell the profiler to use the --quit command line option on the Godot binary. This will exit Godot just after it finished starting. The --quit option works with --editor, --project-manager or --path <path to project directory> (which runs a project directly).

See also

See Command line tutorial for more command line arguments supported by Godot.

Profiler-specific instructions

VerySleepy

  • Start the Godot editor or your project first. If you start the project manager, make sure to edit or run a project first. Otherwise, the profiler will not track the child process since the project manager will spawn a child process for every project edited or run.

  • Open VerySleepy and select the Godot executable in the list of processes on the left:

../../../_images/cpp_profiler_verysleepy_select_process.png
  • Click the Profile All button on the right to start profiling.

  • Perform the actions you wish to profile in the editor or project. When you're done, click Stop (not Abort).

  • Wait for the results window to appear.

  • Once the results window appears, filter the view to remove external modules (such as the graphics driver). You can filter by module by finding a line whose Module matches the Godot executable name, right-clicking that line then choosing Filter Module to <Godot executable name> in the dropdown that appears.

  • Your results window should now look something like this:

../../../_images/cpp_profiler_verysleepy_results_filtered.png

HotSpot

  • Open HotSpot. Click Record Data: