Trying to improve Godot's performance and energy efficiency via compiler optimizations

Hi! My name is Carlos, I’m a computer engineer from Spain, and I’ve been a Godot fan for a few years now :grinning_face: I’ve used the engine in a few personal projects, although this time I am not reaching out to talk specifically about game development :eyes:

A few months ago I finished a research-oriented Master’s degree in Systems and Computer Engineering, and taking advantage of Godot’s open-source nature, I decided to focus my final thesis on studying and trying to improve its performance in the godot-benchmarks repository scenes, focusing exclusively on the engine’s compilation options. The technique I used, which has already been featured in several publications within my research group, consists of using metaheuristics to find sequences of LLVM optimization passes that outperform standard optimization flags (O1, O2, O3, etc.).

In my work, I didn’t manage to outperform the official compilation options specified in the Godot documentation. This may be partly due to the fact that our current methodology only applies optimizations at the LLVM middle-end, leaving potential improvements in other stages of the pipeline that the official build configurations do take advantage of. However, when considering only engine versions optimized at this specific stage, I did obtain results showing notable changes between different optimization levels. And more importantly, I observed specific instances where the pass sequences found via metaheuristics actually outperformed the standard flags, hinting at a potential for improvement over these generic optimizations.

I should mention that this technique, while showing promising results, has one main drawback: finding these optimal sequences of optimization passes requires evaluating thousands upon thousands of valid sequences in search of better ones. This involves not only testing the performance of the program itself, but also applying the optimizations and generating the final binary each time before it can even be tested. This is somewhat manageable for simpler programs, but for a project as large as Godot, it translates to several minutes per evaluation, which has also limited the quality of the preliminary results obtained in my work.

One way to make this approach more practical for Godot could be to focus on specific subsystems rather than the entire engine, saving some time that way. In my thesis, optimizations were applied globally, but targeting components such as the GDScript VM might be a more realistic starting point, particularly given previous discussions like this one: https://github.com/godotengine/godot-proposals/issues/6031

On a related note, I also came across a GitHub issue before starting my work that also explores the potential of tweaking Godot’s compilation process, though I’m unsure of its practical applicability: https://github.com/godotengine/godot-proposals/issues/11431

With that said, I have just begun my PhD studies, and I’m considering dedicating my dissertation to diving deeper into this research. I also want to extend the experimentation to energy consumption reduction, which I believe could be especially interesting for maximizing battery life on handheld devices (and helping the environment in general, of course). My Master’s thesis served as a proof of concept to show that the methodology is applicable and promising, but I thought that before fully committing to this path, it would be good to share my ideas with the community rather than working in total isolation. This way, I can hopefully achieve something truly useful for the engine.

I would greatly appreciate any feedback or questions, and I would be more than happy to talk more in-depth about my work and results if you find it interesting! I would especially love to hear whether you think this direction could realistically benefit the engine, and if there are particular areas where such experimentation would make more sense :godot:

TL;DR: I’m a PhD student researching how to use metaheuristics to find better compiler optimization sequences for Godot, aiming to enhance performance and reduce power consumption. While I haven’t outperformed the official builds overall for the moment, I have identified specific cases with measurable improvement potential. I’d love some community feedback to better align this research with the engine’s needs :slightly_smiling_face:

Note: If there’s a more technical channel or a specific development group where this discussion would be more appropriate, please let me know!

2 Likes

There is a side to this that I feel needs to be brought up. In my experience, performance is rarely a concern automatically high on the list. We all understand how optimization is important and then still it really only makes sense to work on, when there is a specific metric that needs to be but isn’t yet met. That metric is also necessary to tell if one solution is better than another. So I hope your work defines some measurable goal. To me personally, reducing power consumption on mobile kind of sounds interesting, especially if it can be acheived by just switching some flags around.

1 Like

How do you measure performance?

I think that the key point of my proposal lies in what you mentioned at the end. I would say that, when faced with a performance bottleneck in the development of a game, the best thing to do is to locate the underlying cause and try to find more efficient implementations, but, regardless of having a more or less optimal implementation, tuning the optimizations applied by the compiler can lead to “free” gains (in the sense of not having to manually modify the source code of the engine or the game). Furthermore, depending on the characteristics of the game in question, this tuning of compiler optimizations can be directed either exclusively to improve performance or energy efficiency, or to achieve a balance between both (in the case that both objectives are opposite).

On the other hand, I completely agree with you about measurable goals: in order to demonstrate tangible results, well-defined metrics and goals are a must so as to not achieve false gains. And talking about metrics:

Currently, as a first approach, the performance metrics I’ve used to compare different Godot versions compiled with different optimizations are the ones reported by the godot-benchmarks scenes. However, many other metrics could be considered, performance related or not (energy consumption metrics are not reported, for example).