godotengine / godotengine/godot

GDScript function calls have unexpected overhead

Open
#94,752 0 comments 8 reactions 0 assignees View on GitHub
discussion performance topic:gdscript
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

4.2.2 stable

### System information

Linux Vulkan API 1.3.277 Forward Mobile, Cpu Ryzen 4800

### Issue description

Hello, this is my first issue
the code with functions has low performance,
in other languages (rust, python), the same code gives better performance

When assembled, the performance increases, but not much (0,16s-0.17s and 0.6s-0.8s)

this behavior can be considered a bug because the difference is in other languages, but only 3-8% (for rust), 15-24% (for python)

need to be tested on different platforms

```gdscript

extends Node

var iter : int = 1_000_000
var test_strick : float = 0.0
var time : float = 0.0

func sqrt_v1(num:int) -> float:
return num**0.5

func _ready() -> void:
for d:int in range(5):
time = Time.get_unix_time_from_system()
for i:int in range(iter):
test_strick += sqrt_v1(i)
print(Time.get_unix_time_from_system() - time, " =1= ",test_strick)
time = Time.get_unix_time_from_system()
for i:int in range(iter):
test_strick+= i**0.5
print(Time.get_unix_time_from_system() - time, " =2= ",test_strick)
```
output
0.22625708580017 =1= 666666166.458842
0.07334899902344 =2= 1333332332.91772
0.22873187065125 =1= 1999998499.37655
0.07424306869507 =2= 2666664665.8354
0.22937297821045 =1= 3333330832.29431
0.07326412200928 =2= 3999996998.75321
...

### Steps to reproduce

1) Create empty project with 1 node and 1 script
2) paste code
3) run

### Minimal reproduction project (MRP)

N/A

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied GDScript benchmark from the issue and compare the function-call and inlined-loop timings on multiple platforms. Trace the relevant function-call execution path in the engine, then verify that any confirmed overhead is reduced without changing the benchmark's results.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.