Skip to content

Rust-side Variant marshalling#1600

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

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

Conversation

@Bromeon

@Bromeon Bromeon commented May 14, 2026

Copy link
Copy Markdown
Member

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 6 times, most recently from 3a3fc71 to c46ca24 Compare May 18, 2026 19:41
@Bromeon Bromeon force-pushed the perf/variant-rust-marshal branch from c46ca24 to c9bb01f Compare May 23, 2026 14:38
@Bromeon Bromeon force-pushed the perf/variant-rust-marshal branch from c9bb01f to edb4f83 Compare May 31, 2026 10:23
@Bromeon Bromeon force-pushed the perf/variant-rust-marshal branch 2 times, most recently from 05e0e45 to 534abfc Compare June 12, 2026 21:46
Bromeon added 3 commits June 12, 2026 23:52
Marks Variant types that *must* be constructed/destroyed via FFI.
`Extend` pre-allocates from the iterator's size hint, removing per-element grow overhead. The hint is a lower bound only: an over-reporting
iterator appends what it yields and trims unused trailing slots instead of panicking.

`resize_default` complements `resize()` for default-constructible types needing no explicit fill value.
@Bromeon Bromeon force-pushed the perf/variant-rust-marshal branch from 534abfc to eeebe71 Compare June 12, 2026 21:54
POD builtin types (numbers, vectors, color, RID) marshal directly into/from Variant's raw memory layout, skipping Godot FFI for both value
conversion and lifecycle (clone, drop, default).

The `variant-ffi-marshal` feature restores the FFI path for A/B benchmarking. Tests and benchmarks verify both the round-trip correctness and
cross-FFI layout agreement (Godot-created variants decoded by `RustVariant` view and vice versa).
@Bromeon Bromeon force-pushed the perf/variant-rust-marshal branch from eeebe71 to e0aefc5 Compare June 12, 2026 22:16
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