Does UFUNCTION have impact on performance?

Hi

I have a probably silly question.

Does the UFUNCTION or UPROPERTY or USTRUCT or UENUM decorators have impact on code performance? I’m wondering, because those macros aren’t required in many situations (when I don’t want to use this code from blueprints etc.). I wanted to search for variables that have UPROPERTies for no reason but I’m not sure if it is worth the time spend on refactor.

Are UE perform any extra actions for properties and functions that have those decorators?

Not runtime, but compile time.

EDIT: Wait, it does. But just load time, nothing else. Only UPROPERTY().

It does not impact the performence as when you call those function and propeties you normally access them, what UHT does to it (since those macros are empty and does nothing in compile time) it use them to know which functions should be reflected and generates reflection code, which register information about propeties and functions in to memoery, which happens when code module (dll with your code) is loaded and does not take noticable time. Only problem with those macros is it’s bounded with capabilities of reflection system, you can’t use stuff that it does not know.

You don’t need to use those macros if you don’t want to, only required one is UCLASS() on UObject classes, but then editor won’t able to see those things and some engine features require them (like timers and delegates requires reflected function), so if something does not work or crash for odd reason then check if reflecting stuff can fix it. There might be also potential GC problems as engine automaticly deletes objects that are not pointed in any reflected pointer, assuming it a forgotten garbage. I recommand you to use UPROPERTIES on all varables and structs as it let you use commands like “DisplayAll” or “GetAll” allowing to view varable current state which is useful for debuging, it’s a lot better then VS watchers.

Thank You for a thorough answer. The one think I wonder is GC and reflection. Doesn’t GC iterate through bigger list of objects it has to check? I understand that the execution of function itself is like in normal c++, but what about systems that uses those macros to list objects and properties for checking?

I think shipping build don’t use that in large extend as editor does so there should not be concerned. UObjects are forced to use UCLASS() so you won’t avoid GC here, as for property i don’t think adding few pointers of specific type will effect preformence in notable way. GC do check every specific time (every 30 sec by default if i’m not mistaken), so if GC will have too much work the symptoms will be small freeze or drop frames every time he does that

Etherway you want to study it i recomand you to use profiler (Window->Session Frontend) you can have exact info on what takes more time and eats your FPS.

Thanks once again :slight_smile: