Skip to content

Conversation

@Bromeon
Copy link
Member

@Bromeon Bromeon commented Dec 21, 2025

Pull request #1331 performed an optimization for Callables, but changed observable semantics in safeguards-disengaged configuration: the callable name is removed. This may need some more discussion, as there's a small change that some game logic relies on the name (e.g. when stringifying a Callable in GDScript).

This changes the approach, however performs different optimizations:

  • Use CowStr, aka Cow<'static, str> instead of GString when constructing callables
  • Only convert to GString (expensive) lazily, when actually used
  • Cache the GString as well, to avoid recreating it

I measured the #[bench] performance compared to master in Release mode, with both balanced and disengaged safeguards. These are always minimum times.

Benchmark Current BALANCED Master BALANCED Current DISENGAGED Master DISENGAGED
callable_callv_custom 0.067μs 0.065μs 0.039μs 0.031μs 🥀
callable_callv_rust_fn 0.061μs 🌳 0.152μs 0.054μs 0.030μs 🥀
callable_to_string_custom 0.108μs 0.111μs 0.077μs 🌳 0.084μs
callable_to_string_rust_fn 0.084μs 🌳 0.096μs 0.055μs 🌳 0.070μs

Conclusion for this branch:

  • 🌳 to_string is equally fast or faster across the board
  • 🌳 calling is much faster in balanced mode for closures (no change for custom)
  • 🥀 calling is significantly slower in disengaged mode

I would probably merge this due to quite a few other upcoming changes in Callable, but we should maybe revisit perf in disengaged mode. Many people do indeed not care about the callable name, and I don't like that being the thing slowing things down. But I'm also not sure if disengaged should behave differently, this could set a dangerous precedent.

It's quite possible that there are other optimization opportunities, or we make the name behavior more explicit.

cc @lyonbeckers

Provided arguments are mostly string literals, which are cheap to store in `Cow`, but
expensive to convert to `GString`. Doing this on every call can have quite an impact.
Allow caching in RustCallable::callable_name()
@Bromeon Bromeon added this to the 0.5 milestone Dec 21, 2025
@Bromeon Bromeon added c: core Core components performance Performance problems and optimizations labels Dec 21, 2025
@Bromeon Bromeon added this pull request to the merge queue Dec 21, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 21, 2025
@Bromeon Bromeon enabled auto-merge December 21, 2025 21:44
@Bromeon Bromeon added this pull request to the merge queue Dec 21, 2025
Merged via the queue into master with commit c5fe799 Dec 21, 2025
20 checks passed
@Bromeon Bromeon deleted the perf/callable-name branch December 21, 2025 21:57
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.

1 participant