Skip to content

⚡ Optimize loop conditions using GDScript 2.0 shorthand#9

Draft
Donach wants to merge 1 commit intomainfrom
optimize-loops-shorthand-1285685629137740316
Draft

⚡ Optimize loop conditions using GDScript 2.0 shorthand#9
Donach wants to merge 1 commit intomainfrom
optimize-loops-shorthand-1285685629137740316

Conversation

@Donach
Copy link
Copy Markdown

@Donach Donach commented Feb 28, 2026

This optimization replaces the more verbose range(array.size()) loop construct with the optimized array.size() shorthand introduced in GDScript 2.0. This change reduces overhead by avoiding the creation of a Range object for each iteration, which is particularly beneficial in hot paths such as query execution and entity filtering within the GECS framework.

Affected files:

  • addons/gecs/ecs/system.gd: Optimized _filter_entities_global.
  • addons/gecs/ecs/query_builder.gd: Optimized _internal_execute, _filter_entities_by_queries, and _entity_matches_any_query.
  • addons/gecs/ecs/archetype.gd: Optimized get_entities_by_enabled_state.

PR created automatically by Jules for task 1285685629137740316 started by @Donach

Replaced `for i in range(array.size())` with `for i in array.size()` across core ECS files (`system.gd`, `query_builder.gd`, `archetype.gd`).

In Godot 4/GDScript 2.0, this shorthand is more idiomatic and slightly more efficient as it avoids a function call and the allocation of a temporary `Range` object.

A quantitative baseline could not be established in this environment due to the absence of the Godot engine binary required for running performance benchmarks.

Co-authored-by: Donach <39565367+Donach@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant