sgonchar
Topic Author
Posts: 48
Joined: 15 Mar 2021, 22:11

What does NS_BEGIN_COLD_REGION do

16 Apr 2021, 23:05

Hello,

I'm having a hard time finding what NS_BEGIN_COLD_REGION does?
Why it's used in samples, removing/not using it seems to have no ill effects?
Is there a common docs page for existing macros?

Cheers.
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: What does NS_BEGIN_COLD_REGION do

17 Apr 2021, 12:16

We use this macro to mark blocks of code that should be explicitly optimized for size. They are used when implementing the reflection of each class, because even if you are optimizing for speed, the reflection is only executed once and it doesn't make sense to optimize that for speed.

This is a poor approach to PGO (Profile-Guided Optimization). For companies with access to source code like yours, we recommend directly injecting our cpps in your project (we are working to improve this step by having just a few unity files containing all our API) and compiling with PGO enabled to get the best balance between size and speed.

Just inspecting CompilerSettings.h you can see the definitions for Visual Studio:
#define NS_BEGIN_COLD_REGION __pragma(optimize("s", on))
#define NS_END_COLD_REGION __pragma(optimize("", on))
#define NS_COLD_FUNC
And for GCC / Clang:
#define NS_BEGIN_COLD_REGION
#define NS_END_COLD_REGION
#define NS_COLD_FUNC __attribute__((cold, minsize))

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], vinick and 9 guests