Skip to content

Cheaper refcount operations - #1669

Open
Bromeon wants to merge 2 commits into
masterfrom
perf/lean-refcounts
Open

Cheaper refcount operations#1669
Bromeon wants to merge 2 commits into
masterfrom
perf/lean-refcounts

Conversation

@Bromeon

@Bromeon Bromeon commented Jul 30, 2026

Copy link
Copy Markdown
Member

Optimizations:

  • instance-ID lookup for RefCounted operations omitted (statically guaranteed by holding strong-ref)
  • reinterpretation of &RawGd<T> as &RefCounted also without runtime check

Also small refactoring reducing with_ref_counted* functions.

Benchmark

50-54% faster than master (min).

                                              min       median
master:
   -- class_engine_refc_clone_dr ...      0.072μs      0.080μs
   -- class_user_refc_clone_drop ...      0.098μs      0.106μs
   
branch:
   -- class_refc_engine_clone_dr ...      0.033μs      0.034μs
   -- class_user_refc_clone_drop ...      0.049μs      0.050μs

Bromeon added 2 commits July 30, 2026 23:42
No longer does the following:
* instance-ID lookup (statically guaranteed by holding strong-ref)
* reinterpretation of `&RawGd<T>` as `&RefCounted` (another runtime check).
Also make `RefCounted::get_reference_count()` unvalidated, so `maybe_refcount()` can reinterpret instead of rebuilding RTTI.
@Bromeon Bromeon added c: ffi Low-level components and interaction with GDExtension API performance Performance problems and optimizations labels Jul 30, 2026
@GodotRust

Copy link
Copy Markdown

API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1669

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

Labels

c: ffi Low-level components and interaction with GDExtension API performance Performance problems and optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants