+1 vote

This is a "performance" related question.

Le'ts say I have around 50 instances running around, checking 3 different conditions every frame, will the second code be faster than the first one?

func _process(delta):
    if Something_Common and Something_That_Is_Rare and Something_SUPER_rare:
         do_something()

func _process(delta):
     if Something_SUPER_rare and Something_That_Is_Rare and Something_Common:
         do_something()

In other other words, should I ask the engine to check the rarest condition first so he can move on, instead of going all the way every single frame?

in Engine by (16 points)

1 Answer

+2 votes
Best answer

I'm not 100% sure about Godot but every programming language I know of does this.

So yeah, putting them in order from rarest to most common makes sense (or not if checking rarest one would take much longer than the rest).

by (110 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.