GDScript: Improve IF statement performance when using logical and/or expressions#120660
Draft
aurpine wants to merge 1 commit into
Draft
GDScript: Improve IF statement performance when using logical and/or expressions#120660aurpine wants to merge 1 commit into
and/or expressions#120660aurpine wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improve GDScript IF statement performance when
andandoroperators are used. Instead of storing the result of these logical operators, we can use jumps.TODO
Problem
Currently the code
will compile to
Essentially, we are assigning the result of the condition expression to a variable before branching based on the variable. Though it is short-circuiting, the assignment happens regardless.
Solution
Instead of jumping to set a variable, we will directly jump to either the
ifbranch orelsebranch (if applicable).With the fix applied, the generated bytecode for the previous example is
Result
Initial testing shows the change is 30-35% faster when a single operator is used.
Generated bytecode is reduced by up to 79%. Old code would add at least 14 addresses per additional operator, while the new code adds at least 3.
Future Work
Apply similar changes to:
whilematch