GD

GDScript Performance

GDScript performance patterns for Godot 4 including object pooling, physics optimization, and profiling

Details

Language / Topic
gdscriptGDScript
Category
Performance

Rules

balanced
- Move CPU-heavy logic to `_physics_process` (fixed delta) rather than `_process` (variable delta) to prevent frame-rate-dependent behavior and reduce per-frame overhead.
- Use object pooling for frequently spawned/despawned nodes (bullets, particles) — call `hide()` and `set_process(false)` to recycle instead of `queue_free()`.
- Use `@export` node references cached in `_ready()` instead of calling `get_node()` every frame — node path lookups are not free.
- Prefer `StaticBody2D`/`StaticBody3D` for immovable geometry and `CharacterBody2D`/`CharacterBody3D` for player-controlled objects — `RigidBody` has higher simulation cost.
- Use `VisibleOnScreenNotifier2D`/`3D` to pause `_process` on nodes that are off-screen — significantly reduces CPU for large open-world scenes.
- Batch similar draw calls by using `MultiMeshInstance3D` for repeated geometry (grass, trees) instead of individual `MeshInstance3D` nodes.
- Use `Callable.bind()` and `signal.connect()` with `CONNECT_ONE_SHOT` for single-use callbacks to avoid lingering signal connections that accumulate over time.