C++/WinRT ABI interop improvements #1608
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 477 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.369
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1608"
general
weight: 0.35
YexuanXiao
Why
Analysis of the Rust (windows-rs) projection plus code analysis of Windows components that use C++/WinRT showed improvements available to C++/WinRT on two common interop paths — windows-rs boxes scalars and arrays in-process and builds
HSTRINGliterals at compile time.What this PR changes
| Path | Change | Opt-in? |
| :-- | :-- | :-- |
| String |
_hscompile-timeHSTRINGliteral | opt-in || Reference | In-process scalar boxing (u8–u64, float, double, bool, char16, hstring, guid, DateTime, TimeSpan, Point) and array boxing (
IReferenceArray<T>), marshaling by value through combasePropertyValue| transparent |Reference boxing is the largest piece.
box_valueon a scalar or array previously hopped into combase to allocate a generalIPropertyValuecarrying the full discriminated-union machinery. This branch points the scalar and arrayreference_traitsat the in-procimpl::reference<T>/impl::reference_array<T>that already backIReference<T>/IReferenceArray<T>, and makes those a correctIPropertyValue(rightPropertyType, fixedIsNumericScalar, typed getters). A sharedreference_producerCRTP base carries the wholeIPropertyValuesurface and theIMarshaltearoff once; each leaf supplies only its storage and how a getter reads it.To preserve cross-process behavior, stock element types are marked
non_agileand supplyIMarshallazily fromquery_interface_tearoffby building the equivalent combasePropertyValue— so the value still marshals by value, and the combase hop is paid only on marshal, never on box/unbox. Elements whose projected layout differs from the ABI (hstring,DateTime,TimeSpanarrays) and the non-stock element types (IInspectable,Size,Rect) continue to route through combase. This mirrors windows-rs'StockReference.Two deltas vs combase, both matching windows-rs:
GetRuntimeClassNamenow returns theIReference<T>/IReferenceArray<T>runtime class name rather thanWindows.Foundation.PropertyValue, and cross-process the value marshals by value rather than as a proxy.Results
Warmed, order-controlled benchmark of Rust (windows-rs), stock cppwinrt, and
cppwinrt-new(this branch). Rust is Rust→Rust; cppwinrt columns are C++→C++. Average of two reversed-order samples, 4M measured + 2M warmup iterations. Relative results are stable across multiple attempts.| Path | Rust | cppwinrt (stock) | cppwinrt-new | new vs stock | new vs Rust |
| :-- | --: | --: | --: | :-- | :-- |
| Int32 | 14 | 18 | 10 | 1.8× faster | tie |
| String | 14 | 20 | 8 | 2.5× faster | tie |
| Reference | 435 | 2,065 | 541 | 3.8× faster | Rust ~1.2× |
Referenceretains a ~1.2× Rust lead that is structural, not the box shape: cppwinrt's per-object module-lock accounting (alock-prefixed RMW on a process-global at each box's birth/death) plus the CRTmalloc/freelayer vs windows-rs' directHeapAlloc.Testing
New tests:
test/test/reference_boxing.cpp(scalar and arrayPropertyType, numeric conversion, round-trip, array-getter throw behavior, marshal-by-value viaGetUnmarshalClassparity with combase, and cross-STA agile identity through the Global Interface Table) andtest/test_cpp20/hstring_literal.cpp. Built Release/x64;reference_boxingpasses all 61 assertions.References
jonwis/perf-bench(via Copilot)