Skip to content

perf(classic): V8 fast API overloads for WinRT methods with simple signatures - #63

Draft
triniwiz wants to merge 1 commit into
perf/winrt-fast-pass-strings-onlyfrom
perf/winrt-fast-api-calls
Draft

triniwiz wants to merge 1 commit into
perf/winrt-fast-pass-strings-onlyfrom
perf/winrt-fast-api-calls

Conversation

@triniwiz

@triniwiz triniwiz commented Dec 2, 2026

Copy link
Copy Markdown
Member

Stacked on #62.

WinRT methods with simple signatures get a V8 fast API overload, as bound Win32 functions already do (win32_fast.rs).

Which methods

  • Static and instance methods with a single overload per argument count.
  • In-params of Int32, UInt32, Single, Double, Boolean, String, or a runtime class or interface (PointerPlan::Interface).
  • A result that is void, a boolean or a number, and at most six parameters.
  • Everything else keeps the existing callback only: enums, structs, delegates, IReference, collections, out-params and other results. The plan is decided from metadata when the function template is built (winrt_fast::plan) and kept in the method's DeclarationFFI.

The fast call

  • Runs under a callback scope.
  • Target: for an instance method, the receiver's interface pointer comes from receiver_method_call, so it goes through the wrapper's QI cache exactly as the slow callback does. For a static, it's the call prepared once on the class factory.
  • Arguments: numbers and booleans convert directly. Strings pass as fast-pass references. Objects are queried to the parameter's interface.
  • Call: goes through call_registers with [interface, args..., &result]. A failed HRESULT throws.
  • V8 only takes a fast overload when the argument count matches. Other counts reach the slow callback, which still picks the overload for that count.

Performance

x64 Release, measured in an app calling WinRT methods in a loop, best of 9 rounds. Both changes together against the base before #62:

Call Before After
Static (UIElement, Int32, String, Single, Single) -> Boolean 0.46 µs 0.28 µs
Static (UIElement, String, UInt32, Single, Single), empty string 0.23–0.24 µs 0.15–0.16 µs
Instance method (String) on a runtime class 0.32–0.33 µs 0.24–0.28 µs
Instance method (UIElement, Int32 x4) 0.24–0.26 µs 0.21 µs

Correctness was checked in the same loops: 20,000 valid and 20,000 invalid calls return true and false as the slow path does, and the callee's writes land.

Tests
cargo test -p runtime --lib gives the same result as main: 195 passed, and the same 15 failures, which need COM activation, HTTP or a UI dispatcher in that environment. Those tests run unoptimized code, so the fast overloads are covered by the loop checks above.

…gnatures

Static and instance methods whose in-params are Int32, UInt32, Single, Double,
Boolean, String or a runtime class or interface, and whose result is void, a
boolean or a number, get a fast API overload built from metadata. Optimized
callers skip the generic argument marshalling: strings pass as fast-pass
references, objects are queried through the wrapper's interface cache, and the
call goes through the register trampolines Win32 binds already use. Other
methods, and calls with a different argument count, take the existing callback.
@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 33440e04-b133-4c57-b0fd-159115e1d22c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
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