Skip to content

Rust-side Variant marshalling#1600

Draft
Bromeon wants to merge 6 commits into
masterfrom
perf/variant-rust-marshal
Draft

Rust-side Variant marshalling#1600
Bromeon wants to merge 6 commits into
masterfrom
perf/variant-rust-marshal

Conversation

@Bromeon
Copy link
Copy Markdown
Member

@Bromeon Bromeon commented May 14, 2026

For Variant holding Copy builtin types (or rather those that don't need an FFI constructor/destructor), we can emulate Godot's Variant layout directly in Rust. This saves a large number of FFI calls for just Variant conversions and has the potential to speed up operations across the board.

@Bromeon Bromeon added c: core Core components performance Performance problems and optimizations labels May 14, 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-1600

@Bromeon Bromeon force-pushed the perf/variant-rust-marshal branch 5 times, most recently from 2c3233f to 3a3fc71 Compare May 15, 2026 10:24
Bromeon added 6 commits May 18, 2026 16:23
Generated from `has_destructor` in `extension_api.json`. Used internally
to detect POD types eligible for rust-side variant marshalling.
…fast `Extend`

`Extend` pre-allocates via `size_hint` and writes variants directly into slots.
Panics on iterator under-yield (size_hint contract violation).
POD builtins bypass FFI via inline-memory marshalling. Dispatch is internal:
`rust_to_variant`/`rust_from_variant` select the path. `RustMarshal: GodotType<Ffi = Self>`
documents the contract -- the type IS its own FFI carrier.
`Variant::default()` returns `mem::zeroed()` (NIL is type-tag 0 with zeroed data).
`Variant::clone()` performs a bytewise `ptr::read` for POD types; non-POD falls through to `variant_new_copy` FFI.
`Variant::drop()` skips `variant_destroy` for POD types, as it is a no-op for them in Godot.

All three fast paths are gated on `#[cfg(not(feature = "variant-ffi-marshal"))]` so A/B benchmarks keep working.
Tests roundtrip via public API and direct `RustVariant` view for all `RustMarshal` types.
Benches: `Array::extend` size-hint fast path, packed-to-typed conversion.
@Bromeon Bromeon force-pushed the perf/variant-rust-marshal branch from 3a3fc71 to c46ca24 Compare May 18, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c: core Core components performance Performance problems and optimizations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants