Repository navigation
Use a shared helper for cached activation factories to reduce binary size - #2678
Merged
Sergio Pedri (Sergio0694) merged 1 commit intoDec 3, 2026
Conversation
Replace the generated per-factory getters (a null check plus an 'IsInCurrentContext' check, with an inlined fallback) with a one-line semi-auto property over 'WindowsRuntimeObjectReference.GetActivationFactory(ref field, ...)'. The fast path (free-threaded factories) is inlined, and the context-aware and resolution logic lives in a shared non-inlined slow path. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sergio Pedri (Sergio0694)
requested a review
from Manodasan Wignarajah (manodasanW)
December 2, 2026 23:22
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Manodasan Wignarajah (manodasanW)
approved these changes
Dec 3, 2026
Sergio Pedri (Sergio0694)
deleted the
sergio0694-activation-factory-size-reduction
branch
December 3, 2026 08:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
4540897d62fb7084f4d373d00adb845564fbc56a↑ Native
WinStore.App.dllmeasured 62,464 B smaller against an identical baseline, with CsWinRT version in effect confirmed per run.↑ Independent Opus 5.5 review found behavioral equivalence with the old getter and no blocking issues.
↓
ProjectionWriterTesthung locally and was stopped, so no result; no other test suites were run.↓ CI results not inspected yet.
Summary
Replaces the generated per-factory getters for cached activation factories with a one-line semi-auto property over a shared runtime helper,
WindowsRuntimeObjectReference.GetActivationFactory(ref field, "TypeName", iid). This is a pure binary size reduction: there is no behavior change.Motivation
Every projected runtime class (and every static/factory/composable interface) used to get a multi-line getter that reads the cached factory, checks
IsInCurrentContext(a virtual call whose guarded devirtualization got inlined into each getter), and falls back to resolving a new factory. That code is duplicated thousands of times across the Windows SDK, XAML and 3rd party projections. The new helper keeps only a small inlined fast path for free-threaded factories (the common case), and moves the context-aware check and resolution into a single shared[NoInlining]slow path.Changes
src/WinRT.Runtime/.../WindowsRuntimeObjectReference.Activation.cs: newGetActivationFactory(ref location, runtimeClassName[, in iid])overloads, with an inlined fast path for free-threaded factories and a[NoInlining]GetOrResolveActivationFactoryslow path (context-aware validation, then resolve and cache). The slot is accessed withVolatile.Read/Volatile.Write; if multiple threads resolve concurrently, the last stored wins (same as before). The defaultIActivationFactoryoverload passes a nullref Guidthat the slow path detects withUnsafe.IsNullRef.src/WinRT.Projection.Writer/Factories/(ClassFactory.cs,ConstructorFactory.AttributedTypes.cs): all cached activation factory properties (default, static, factory and composable) are emitted asprivate static WindowsRuntimeObjectReference _objRef_* => WindowsRuntimeObjectReference.GetActivationFactory(ref field, ...), through a single shared emitter.docs/: updated the generated code samples inruntime-class-projections.mdandevent-infrastructure.md.Binary size
Store app (Release, x64, Native AOT, public feature level, CsWinRT 3.0 leg
net10.0-windows10.0.28000.1), same Store commit and clean outputs for both runs, differing only in the CsWinRT package: currentstaging/3.0(ec233e6d8) vs. this change (both built locally with the samebuild.cmd ... productflow; the CsWinRT version in effect was confirmed inproject.assets.jsonfor each run). Only the nativeWinStore.App.dllsize is considered.staging/3.0WinStore.App.dll(native)WinRT.Sdk.Projection.dllWinRT.Sdk.Xaml.Projection.dllWinRT.Projection.dllWinRT.Interop.dllThe native size is deterministic: rebuilding the baseline gave a byte-identical size.
WinRT.Runtime.dllgrows by 512 B.