1- :article_outdated: True
2-
31.. _doc_general_optimization :
42
53General optimization tips
64=========================
75
86Introduction
9- ~~~~~~~~~~~~
7+ ------------
108
119In an ideal world, computers would run at infinite speed. The only limit to
1210what we could achieve would be our imagination. However, in the real world, it's
@@ -48,7 +46,7 @@ But in reality, there are several different kinds of performance problems:
4846Each of these are annoying to the user, but in different ways.
4947
5048Measuring performance
51- =====================
49+ ---------------------
5250
5351Probably the most important tool for optimization is the ability to measure
5452performance - to identify where bottlenecks are, and to measure the success of
@@ -57,19 +55,24 @@ our attempts to speed them up.
5755There are several methods of measuring performance, including:
5856
5957- Putting a start/stop timer around code of interest.
60- - Using the Godot profiler.
61- - Using external third-party CPU profilers.
62- - Using GPU profilers/debuggers such as
63- `NVIDIA Nsight Graphics <https://developer.nvidia.com/nsight-graphics >`__
64- or `apitrace <https://apitrace.github.io/ >`__.
65- - Checking the frame rate (with V-Sync disabled).
58+ - Using the :ref: `Godot profiler <doc_the_profiler >`.
59+ - Using :ref: `external CPU profilers <doc_using_cpp_profilers >`.
60+ - Using external GPU profilers/debuggers such as
61+ `NVIDIA Nsight Graphics <https://developer.nvidia.com/nsight-graphics >`__,
62+ `Radeon GPU Profiler <https://gpuopen.com/rgp/ >`__ or
63+ `Intel Graphics Performance Analyzers <https://www.intel.com/content/www/us/en/developer/tools/graphics-performance-analyzers/overview.html >`__.
64+ - Checking the frame rate (with V-Sync disabled). Third-party utilities such as
65+ `RivaTuner Statistics Server <https://www.guru3d.com/files-details/rtss-rivatuner-statistics-server-download.html >`__
66+ (Windows) or `MangoHud <https://github.com/flightlessmango/MangoHud >`__
67+ (Linux) can also be useful here.
68+ - Using an unofficial `debug menu add-on <https://github.com/godot-extended-libraries/godot-debug-menu> `.
6669
6770Be very aware that the relative performance of different areas can vary on
6871different hardware. It's often a good idea to measure timings on more than one
6972device. This is especially the case if you're targeting mobile devices.
7073
7174Limitations
72- ~~~~~~~~~~~
75+ ^^^^^^^^^^^
7376
7477CPU profilers are often the go-to method for measuring performance. However,
7578they don't always tell the whole story.
@@ -87,7 +90,7 @@ As a result of these limitations, you often need to use detective work to find
8790out where bottlenecks are.
8891
8992Detective work
90- ~~~~~~~~~~~~~~
93+ --------------
9194
9295Detective work is a crucial skill for developers (both in terms of performance,
9396and also in terms of bug fixing). This can include hypothesis testing, and
@@ -119,7 +122,7 @@ Once you know which of the two halves contains the bottleneck, you can
119122repeat this process until you've pinned down the problematic area.
120123
121124Profilers
122- =========
125+ ---------
123126
124127Profilers allow you to time your program while running it. Profilers then
125128provide results telling you what percentage of time was spent in different
@@ -133,7 +136,7 @@ and lead to slower performance.
133136For more info about using Godot's built-in profiler, see :ref: `doc_the_profiler `.
134137
135138Principles
136- ==========
139+ ----------
137140
138141`Donald Knuth <https://en.wikipedia.org/wiki/Donald_Knuth >`__ said:
139142
@@ -163,7 +166,7 @@ optimization is (by definition) undesirable, performant software is the result
163166of performant design.
164167
165168Performant design
166- ~~~~~~~~~~~~~~~~~
169+ ^^^^^^^^^^^^^^^^^
167170
168171The danger with encouraging people to ignore optimization until necessary, is
169172that it conveniently ignores that the most important time to consider
@@ -178,7 +181,7 @@ will often run many times faster than a mediocre design with low-level
178181optimization.
179182
180183Incremental design
181- ~~~~~~~~~~~~~~~~~~
184+ ^^^^^^^^^^^^^^^^^^
182185
183186Of course, in practice, unless you have prior knowledge, you are unlikely to
184187come up with the best design the first time. Instead, you'll often make a series
@@ -195,7 +198,7 @@ structures and algorithms for *cache locality* of data and linear access, rather
195198than jumping around in memory.
196199
197200The optimization process
198- ~~~~~~~~~~~~~~~~~~~~~~~~
201+ ^^^^^^^^^^^^^^^^^^^^^^^^
199202
200203Assuming we have a reasonable design, and taking our lessons from Knuth, our
201204first step in optimization should be to identify the biggest bottlenecks - the
@@ -212,7 +215,7 @@ The process is thus:
2122153. Return to step 1.
213216
214217Optimizing bottlenecks
215- ~~~~~~~~~~~~~~~~~~~~~~
218+ ^^^^^^^^^^^^^^^^^^^^^^
216219
217220Some profilers will even tell you which part of a function (which data accesses,
218221calculations) are slowing things down.
@@ -237,10 +240,10 @@ positive effect will be outweighed by the negatives of more complex code, and
237240you may choose to leave out that optimization.
238241
239242Appendix
240- ========
243+ --------
241244
242245Bottleneck math
243- ~~~~~~~~~~~~~~~
246+ ^^^^^^^^^^^^^^^
244247
245248The proverb *"a chain is only as strong as its weakest link" * applies directly to
246249performance optimization. If your project is spending 90% of the time in
0 commit comments