Skip to content

perf(classic): pass in-param strings as fast-pass HSTRING references - #62

Merged
triniwiz merged 2 commits into
mainfrom
perf/winrt-fast-pass-strings-only
Dec 2, 2026
Merged

triniwiz merged 2 commits into
mainfrom
perf/winrt-fast-pass-strings-only

Conversation

@triniwiz

@triniwiz triniwiz commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

In-param strings now pass as fast-pass HSTRING references (WindowsCreateStringReference), in both the classic MethodCall::call and the napi engine's call_napi.

Change

  • The JS string's UTF-16 is copied into per-call storage: 64 code units inline, larger strings on the heap.
    • Classic copies it with write_v2.
    • napi writes it in place with napi_get_value_string_utf16, so neither the Vec from into_utf16() nor the HSTRING copy remains.
  • The header and buffer live for the call, which is all an in-param needs; a callee that keeps the string duplicates it.
  • Each string used to cost a Vec<u16> plus a heap HSTRING copy. A reference needs neither, and nothing is released after the call.
  • Strings that arrive as HSTRING-backed objects still reuse their handle as before.

Performance

x64 Release, classic engine, measured in an app calling WinRT statics in a loop, best of 9 rounds.

Call Before After
A static taking (UIElement, Int32, String, Single, Single), short string 0.45–0.51 µs 0.36–0.39 µs

Tests
cargo check -p runtime --no-default-features --features napi_engine passes. 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.

@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: 7c0d1b4e-5c3b-4ee4-9f1c-f80f4280a34a

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

napi writes a string argument's UTF-16 straight into per-call storage, wrapped
with WindowsCreateStringReference, instead of a Vec plus a heap HSTRING.
@triniwiz
triniwiz marked this pull request as ready for review December 2, 2026 01:21
@triniwiz
triniwiz merged commit baa5c62 into main Dec 2, 2026
6 checks passed
@triniwiz
triniwiz deleted the perf/winrt-fast-pass-strings-only branch December 2, 2026 01:21
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