-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply basic optimizations in GDScript compiler #7823
Comments
Thank you for your proposal, closing as a duplicate of: This tracks the wider context of performance improvements of GDScript |
This is about compiler part, while Improve the performance of the GDScript VM #6031 mainly focus on the VM performance, I don't find any discussion about compile-time optimization in that proposal. |
It does talk about the wider topic and not just the VM (I have discussed in it myself and those topics were brought up) |
Well I use Ctrl+F and miss your comment, sorry for that. But the majority of that proposal is still about compile to C, LLVM, wasm, ... and seems nobody reply to your comment, I wonder if they really want to talk about this topic after 100 floor of transpiling stuff. I open this proposal because I want to take a try in contributing and want some advise, and this is definitely a small topic, not about a large gdscript rework. Anyway I will copy above to that proposal since it is not totally unrelated. |
Test code
func _process(delta: float) -> void:
for i in range(1_000_000):
pass frame_time: 12ms
func _process(delta: float) -> void:
var a := 0
for i in range(100_000):
var b := a frame time: 1.6ms func _process(delta: float) -> void:
var a := 0
for i in range(100_000):
var b := a
var c := b
var d := c frame time: 4.9ms
func _process(delta: float) -> void:
var a := 0
var b := 1
for i in range(100_000):
var c := (a + b) frame time: 2.2ms func _process(delta: float) -> void:
var a := 0
var b := 1
for i in range(100_000):
var c := (a + b) + (a + b) + (a + b) + (a + b) frame time: 6.9ms
func _process(delta: float) -> void:
const a := 0
for i in range(100_000):
var b := a frame time: 1.7ms func _process(delta: float) -> void:
for i in range(100_000):
const a := 0
var b := a frame time: 2.1ms I test these snippets on my dev build ( |
Describe the project you are working on
Currently looking around in godot source code and trying to contribute.
Describe the problem or limitation you are having in your project
Some quick test shows that GDScript compiler seems to lack the ability to do some simple optimizations.
Test code snippets attached below.
I find lots of PR and issues trying improve GDScript VM performance, however I don't see any about the compiler (Let me know if there is some).
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Implement these optimizations in GDScript compiler. They can help to improve overall performance of user scripts.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
These are standard compiler optimizations, you can find detailed description on wiki.
Constant Folding
Common subexpression elimination
Loop-invariant code motion
If this enhancement will not be used often, can it be worked around with a few lines of script?
While in simple cases, one paradigm alone can be overcome by manually optimize the source script, complex case or multiple paradigms combining together increase its difficulty. Also sometimes applying these paradigms may produce ugly or hard to maintain code. So developers may refuse to do these optimizations because this waste too much time with relative small peformance gain or they prefer cleaner code. Having these work done in compiler benifits all GDScript users.
Is there a reason why this should be core and not an add-on in the asset library?
This proposal is about GDScript compiler, which is part of Godot.
The text was updated successfully, but these errors were encountered: