5 ms·
In most C++ game engines the standard library is almost never used, for performance reasons. See: https://github.com/electronicarts/EASTL https://github.com/el
by kcbanner 7y ago
In most C++ game engines the standard library is almost never used, for performance reasons.
See:
https://github.com/electronicarts/EASTL https://github.com/electronicarts/EASTL
- favorited 7y agoPerformance in debug builds is a particular issue, since getting acceptable-for-gamedev machine code from modern C++ often requires optimized builds. http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/ http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/
- hermitdev 7y agoFor MSVC, the debug checks are fairly customizable through judicious use of appropriate debug macros. One can also enabled optimizations with debug symbols, but the debugging experience can be jarring. I'm not a game developer, but have spent a decade doing C++ on Windows, and at former employer, we had several different debugging profiles depending on the severity/difficulty of reproducing/debugging an issue. Our "normal" debug profile had all of the debug checks in the std lib disabled, and we could only effectively debug our own code. Not sure if games dont do this, or if its still not performing enough.
- daemin 7y agoOne problem with using different debug macros in your debug build is that any libraries you link in must also be using the same flags. This is not necessarily possible for binary releases as they will assume certain standard library flags to exist in the debug builds (like iterator checking levels). At work we don't use a debug build in the traditional sense, it's what you call a no-optimisations build where the code is compiled without most optimisations but otherwise the flags are the same as a release build. Some teams also go a step further and compile most of the code in release but some of their code with optimisations disabled.
- hermitdev 7y ago> One problem with using different debug macros in your debug build is that any libraries you link in must also be using the same flags. They don't have to be, but it certainly makes this world's easier. If the flags are not the same, for sure you have to be very careful about passing objects between DLL boundaries. At the companies I've done C++ work at, we've always had the source for all non C libs and compiled any C++ libs our selves (except for Windows libs, bit they also provide checked debug libs), so we could control the flags.
- gpderetta 7y agoMy understanding the primary reason for he developers using custom libraries is not so much performance but a) historically console compilers and expecially standard libraries have been extremely buggy and b) is good to have a single implementation across platforms instead of having to deal with quirks and implementation divergence.
- lasagnaphil 7y agoFrom what I've heard, there are two more major reasons to not use STL for gamedev. - Debug build performance. Release builds of C++ code using STL are generally pretty fast, but Debug builds suffer a lot (especially Visual Studio's std::vector implementation is notoriously horrible for debug builds). Debug executable speeds matter when you are debugging a game; you don't want to test your first-person shooter in 1 FPS! - Build speed. Because of heavy use of templates and historical cruft, STL slows down your build times a lot. The build-test cycle is very important when designing games; you don't want to wait for a few hours after you've changed a few lines of code to tweak a new feature. Gigantic distributed build servers alleviates this problem a bit, but they are pretty cumbersome to set up nonetheless.
- lenkite 7y agoAre all those "best practices" valid for modern C++ ? I mean one statement says "Pass and return containers by reference instead of value.". This is in contradiction to modern C++ where you return containers by value and rely on copy-elison/RVO. https://stackoverflow.com/questions/15704565/efficient-way-to-return-a-stdvector-in-c https://stackoverflow.com/questions/15704565/efficient-way-t...
- daemin 7y agoThe best way to tell is to try it the modern way and then look at the assembly code generated on something like godbolt.org. If it ends up being less efficient then you change it to accept a non-const reference to store the result in as a parameter instead. Though if you'll be calling the same function repeatedly to accumulate content into a single container it is far more efficient to have a function with an output reference rather than returning a new container. This will result in fewer memory allocations and you can also pre-allocate the size once before calling those functions. On the part of tooling it might be nice if there was a way to annotate a function so that it creates a warning if the compiler cannot use copy-elision for the return value. (To be honest I haven't checked the documentation for this specific thing)
- gpderetta 7y agoCopy elision is now mandated in many (but not all) cases FWIW.
- daemin 7y agoThe warning that I would want would trigger when someone changes the function and prevents or suppresses copy elision from happening. Like for example adding a check at the start of the function and returning a default container.
- gpderetta 7y agomaking the returned object non copyable, non movable is a an option. edit: also, the rule is simple: RVO is always mandated, NRVO remains an optimization.