Search Unity

Discussion Add LTO, PGO and PLO recommendations to IL2CPP documentation

Discussion in 'Documentation' started by zamazan4ik, Dec 8, 2023.

  1. zamazan4ik

    zamazan4ik

    Joined:
    Dec 8, 2023
    Posts:
    1
    Hi!

    I want to propose adding recommendations about using more advanced compiler optimization techniques for C++ compilers in case of using IL2CPP build: Link-Time Optimization (LTO), Profile-Guided Optimization (PGO), Post-Link Optimization (PLO).

    Link-Time Optimization (LTO) is a well-known compiler optimization that allows cross-translation-unit (TU) optimizations. It improves code size, enables better inlining decisions, devirtualization, etc. All major compilers (MSVC, Clang, GCC, and many proprietary compilers) have supported it for years.

    LTO is generally enabled for multiple software by default nowadays:

    Some examples of performance improvements from enabling LTO:

    More about LTO you can read here: https://convolv.es/guides/lto/

    Profile-Guided Optimization (PGO) is a compiler optimization technique that optimizes an application based on a previously collected runtime profile (also known as a PGO profile). PGO allows to a compiler decide much more precisely about the best inlining decisions, make better code layout decisions, etc. All major C++ compilers (MSVC, Clang, GCC) support PGO for years.

    For gamedev domain, I have the following related materials about PGO:

    Much more materials, benchmark results, etc. about PGO you can find in my repo: https://github.com/zamazan4ik/awesome-pgo

    I found at least one post about PGO before on the forum - https://forum.unity.com/threads/windows-standalone-il2cpp-debugging-vs-solution.524991/ .

    Post-Link Optimization (PLO) is a quite new optimization technique that optimizes applications for better CPU I-cache utilization. The major tool in this area right now is LLVM BOLT (https://github.com/llvm/llvm-project/blob/main/bolt/README.md). However, the main limitation here would be that BOLT does not support the Windows platform yet (I guess the Windows platform is a major platform for Unity) - BOLT supports only Linux for now.

    Here I collected some materials about BOLT benchmarks for applications:
    I think all of these recommendations can be valuable for users who want to optimize their games for better CPU utilization (and hopefully reduce CPU requirement for their games).

    I would be happy to answer your questions.
     
    tw00275 likes this.