Repository navigation
Defer creating default values that a write would hide - #41183
Merged
Merged
Conversation
BindableObject ran DefaultValueCreator when the first write to a property created its context, and kept the created default under the written value. Properties can now opt in (BindableProperty.WithDeferredDefaultValueCreation) to a placeholder default that is created only when something can observe it: a read while it is the effective value, a clear, a binding, a dynamic resource or an animation. Opt in Border.StrokeShape, Border.StrokeDashArray and Grid.Row/ColumnDefinitions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
GetContext now creates a deferred default value only while it is the effective value, so top-only readers (GoToState, HasVisualState, diagnostics) keep it deferred; clearing, binding removal and animations use GetContextForUpdate. Opt in VisualStateGroups, whose style setters created a throwaway default list per styled element. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
A survey of every default value creator in the sample app (startup and navigation) found these two still created by writes and never observed: FontSize computes the default font size for every IFontElement whose size a style or the page sets, and ItemsView allocates a LinearItemsLayout under each explicitly set ItemsLayout. Their callbacks ignore or accept a null/0 old value. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
1 of 2 tasks
Contributor
MAUI Autopilot — Waiting for the Copilot API rate limit@kubaflo The MAUI expert review hit the Copilot API rate limit (429). The loop tries again every 15 minutes, for up to 6 hours after it started. Run. Error |
- Grid: subscribe a restored default definitions collection once. Its creator already subscribes, so ClearValue left it subscribed twice and one subscription survived a later replacement. - Keep the default deferred when its creator throws, so a retry creates it instead of exposing the placeholder. - A write at DefaultValue specificity replaces the placeholder; reads and clears no longer overwrite it with a created default. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 of 2 tasks
kubaflo
added a commit
that referenced
this pull request
Dec 4, 2026
… resume (#41220) <!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `2277fc6429ef728d0c7a72021cac627685b9473b` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 9/10 | ↑ Only the runner of the two jobs that hold the 15-minute waits changes; both keep `timeout-minutes: 25`.<br>↑ gh-aw compiled both workflows; each lock changes only that runner and its metadata hash.<br>↓ No live rate-limit wait has run on the new runner yet. | | Diagnosis confidence | 9.5/10 | ↑ All five rate-limited loops' wait jobs ended `cancelled` 15:00–15:03 after starting, despite `timeout-minutes: 25`.<br>↑ GitHub documents that ubuntu-slim jobs are limited to 15 minutes of execution time. | | Evidence fit | 9.5/10 | ↑ #41188, #41182 and #41183 are still open with `s/autopilot-rate-limited`, and no Autopilot run has picked them up since; #41204 and #41195 merged with the same stale labels. | <!-- /copilot-assessment --> <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change <!-- Enter description of the fix in this section --> When the expert review or a fix round hits the Copilot API rate limit (or a ghcr.io outage), the job labels the PR `s/autopilot-rate-limited`, waits 15 minutes, and dispatches the next round. Both jobs that hold that wait run on `ubuntu-slim`, which [ends every job at 15 minutes](https://github.blog/changelog/2026-01-22-1-vcpu-linux-runner-now-generally-available-in-github-actions/). The wait starts after the job's own work, so the runner cancels it before the dispatch, and the loop silently stalls. On 2026-12-03 this stalled all five rate-limited loops. In expert runs [47218604696](https://github.com/dotnet/maui/actions/runs/47218604696) (#41188), [47218665214](https://github.com/dotnet/maui/actions/runs/47218665214) (#41182), [47218667908](https://github.com/dotnet/maui/actions/runs/47218667908) (#41183), [47218477536](https://github.com/dotnet/maui/actions/runs/47218477536) (#41204) and [47218571510](https://github.com/dotnet/maui/actions/runs/47218571510) (#41195), `autopilot_failed` ended `cancelled` 15:00–15:03 after it started. All five PRs still carry `s/autopilot-running`. This moves `autopilot_failed` (copilot-review-expert) and `next_round` (maui-expert-autopilot), the only jobs with the 15-minute wait, to `ubuntu-latest`. Their existing 25-minute timeouts already cover the wait. Nothing else changes. Validation: `gh aw compile maui-expert-autopilot copilot-review-expert --no-check-update` (v0.86.2) passed with the existing warnings; each lock diff is the runner line plus its metadata hash; `git diff --check` passed. No live dispatch was run. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Observed on #41188, #41182, #41183, #41204 and #41195. ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, keep "Allow edits by maintainers" on so the agent can push to your branch; otherwise it opens a follow-up PR that keeps your commits. <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
kubaflo
added a commit
that referenced
this pull request
Dec 4, 2026
<!-- copilot-assessment:v1 --> ### Agent assessment Self-reported assessment, not an independent review. Assessed revision: `37924361ead9e9b6fc4e13f4415f731ffb148ad4` | Dimension | Assessment | Rationale | |---|---|---| | Change confidence | 8.5/10 | ↑ Every rule is backed by a fix report and PR diff from the startup-allocation work; cited test names and APIs were checked against `main` or the PR diffs.<br>↑ Relative links and anchors checked by script; `Review-Expert.Tests.ps1` passes 13/13 (routing hash unchanged).<br>↑ Wording tightened about 30% (3,954 → 2,789 added words) with the same rules and examples; checks rerun.<br>↑ Three-model review (gpt-6.2-sol, gemini-4-neon, mai-code-2): 8 accuracy findings fixed, 1 dismissed (YAML-list `applyTo` is the repo-wide convention), none critical.<br>↓ Most cited PRs are still open, so some referenced types (`ScalableEventHandler<T>`, `StaticResourceResolver`, `WeakEventProxyFinalizer`) aren't on `main` yet.<br>↓ Documentation only; usefulness to agents is unmeasured. | <!-- /copilot-assessment --> <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change About 20 fixes recently cut startup and navigation allocations in the `--sample-content` template app (Android, Pixel 10): #41149, #41152, #41153, #41154, #41161, #41162, #41163, #41165, #41166, #41180, #41181, #41182, #41183, #41184, #41185, #41186, #41188, #41198–#41202, #41205. This PR turns the recurring causes into path-scoped guidance so agents and contributors don't reintroduce them. **New** - `.github/instructions/controls-core-performance.instructions.md` (`src/Controls/src/Core/**`): create rarely used per-element state lazily; `GetValue`/`SetValue` on creator-backed or default-valued properties allocate; don't use an `Element` as a helper or return one from per-map getters; don't build notifications nobody receives; many subscribers on a shared object must scale linearly; one table per target, no weak ref or box per target; no finalizers on element types; no per-call closures, boxed enumerators or iterators; don't build invisible UI. Each rule has a short why, a do/don't snippet or real type, and the PR. - `.github/instructions/sourcegen-performance.instructions.md` (`src/Controls/src/SourceGen/**`): no per-instance service providers, reflection, wrappers or compile-time-only markup-extension objects; version-skew fallback; Incremental Hot Reload gate; measure with XAML diagnostics off. - `docs/design/MeasuringAllocations.md`: choosing a measurement, pitfalls (`EnableMauiDiagnostics`, `StartupNoGCRegion`, sampled stacks, analyzer and gcdump traps), the device workflow, and the allocation-count unit test pattern with existing examples on `main`. **Updated** - `android.instructions.md`: Java peers and JNI cost (per-view listeners, `-=` without `+=`, `AnimatedValue`, `FindViewWithTag`, per-draw `Rect`/`Paint`, caching display info, peer-count device tests). - `performance-hotpaths.instructions.md`: Graphics platform, `PathF` and `ArcFlattener` scope; allocation-free getters, scratch objects, analytic computation, regression tests. - `templates.instructions.md`: runtime cost of per-item template content. - `copilot-instructions.md`: one pointer under Performance measurements. - `maui-expert-reviewer.md`: review checks for these regressions (outside the hashed routing section). Validation: link/anchor check script over changed Markdown (0 broken); `Invoke-Pester .github/scripts/Review-Expert.Tests.ps1`: 13 passed, 0 failed. No code changes, so no builds or unit tests were run. ### Issues Fixed None; documentation follow-up to the PRs above. ### Let AI finish this PR - [ ] **Let the MAUI agent address review feedback and fix remaining issues on this PR.** Maintainers still decide whether it is merged. For PRs from forks, keep "Allow edits by maintainers" on so the agent can push to your branch; otherwise it opens a follow-up PR that keeps your commits. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
kubaflo
approved these changes
Dec 4, 2026
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:
e2e250de361af03a2b8235f9cd2403ba5a45ffef↑ 17 focused tests, including 3 for findings from a three-model code review (Grid double subscription, throwing creator, writes at default specificity); each fails without its fix.
↑ A device A/B on a Pixel 10 confirmed the allocation and retention savings.
↓ Device tests and UI tests were not run, and the device measurement predates the merge with main.
↓ For opted-in properties, the first write's oldValue and same-as-default writes behave differently by design.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Target Branch
mainnet11, for reviewFor .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into
net11; agents must not retarget or merge.Description of Change
When a write is the first thing to touch a property that has a
DefaultValueCreator,BindableObjectruns the creator. The created default is then kept underneath the written value for the element's lifetime. For example, everyBorderwhoseStrokeShapeis set still allocates and keeps a full defaultRectangleView, about 3 KB.This PR adds an internal opt-in,
BindableProperty.WithDeferredDefaultValueCreation(). When a write creates the property's storage, the default slot holdsDefaultValueas a placeholder and the storage is flaggedIsDefaultValueDeferred. The real default is created the moment something can observe it:GetValue, typedGetValue,GetContext,GetValues, the local-value enumerator);ClearValue,RemoveBindingand the animation paths, which go through the newGetContextForUpdate, plusSetBindingand dynamic resources;IsSetandIsSetExplicitlynever create the default, and their results don't change.Opted in:
Border.StrokeShapeBorder.StrokeDashArrayGrid.RowDefinitionsandGrid.ColumnDefinitionsVisualStateManager.VisualStateGroupsIFontElement.FontSizeItemsView.ItemsLayoutEach opted-in property was checked for three things: its creator has no side effects beyond the object it returns, its callbacks accept
DefaultValueas the old value, and an extra change notification from writing exactly the default is harmless.Behavior differences, on opted-in properties only:
oldValuepassed topropertyChanging/propertyChangedisDefaultValue(usuallynull) instead of a created default nobody saw.FontSizeequal to the default) raises a change where it used to be a no-op.Public
BindableProperty.Createis unchanged, because third-party callbacks may depend on the old behavior.How we found which properties to opt in. A temporary build of the default
--sample-contenttemplate app counted, for every property with a default creator, the defaults created by writes and whether anything ever read them later. The app ran on a Pixel 10 (Release, android-arm64) through startup and navigation. No write-created default was ever read. The opted-in properties account for nearly all of the retained waste.Before/after (same tree with deferral switched off, 8 alternating runs each):
Rectangles retainedVisualStateGroupLists retainedThe numbers above were measured before
FontSizeandItemsLayoutwere opted in. Over a navigation scenario, those two add about 11.5 KB of avoided allocation and 3.5 KB of avoided retention.Tests run (after merging
origin/main; Controls.Core.UnitTests rerun at the latest revision: 8362 passed, 0 failed):dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj: passed. 8359 passed, 0 failed, 30 skipped.dotnet test src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj: passed. 1694 passed, 0 failed, 3 skipped.Interactions: this touches
BindableProperty.CreateContext(newdeferDefaultValueparameter),GetContextand a new context attribute bit (1 << 6). Conflicts with the in-flight typed-storage and context-slimming work should be mechanical.Issues Fixed
Related to #34149
Related to #34159
Let AI finish this PR