Skip to content

BindableObject micro-optimizations#33460

Merged
rmarinho merged 1 commit intodotnet:mainfrom
albyrock87:bindable-object-micro-optimizations
Jan 19, 2026
Merged

BindableObject micro-optimizations#33460
rmarinho merged 1 commit intodotnet:mainfrom
albyrock87:bindable-object-micro-optimizations

Conversation

@albyrock87
Copy link
Contributor

Description of Change

image

In collection view, where the binding context changes frequently, it is important for the base class BindableObject to be super efficient.

In this case I'm doing some micro optimizations (avoiding a foreach when not needed) and moving Shell related attached properties' binding context propagation to Page (the only real target of those properties).

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jan 10, 2026
@dotnet-policy-service
Copy link
Contributor

Hey there @@albyrock87! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@albyrock87 albyrock87 force-pushed the bindable-object-micro-optimizations branch from 28384ac to 92812a8 Compare January 10, 2026 14:00
@kubaflo
Copy link
Contributor

kubaflo commented Jan 17, 2026

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@kubaflo
Copy link
Contributor

kubaflo commented Jan 17, 2026

PR Review: #33460 - BindableObject micro-optimizations

Date: 2026-01-17 | Issue: None | PR: #33460

✅ Final Recommendation: APPROVE

Justification: This PR implements a well-designed performance optimization with correct semantics.

Phase Status
Pre-Flight ✅ COMPLETE
🧪 Tests ✅ COMPLETE
🚦 Gate ✅ PASSED
🔧 Fix ✅ COMPLETE
📋 Report ✅ COMPLETE

📋 Issue Summary

Type: Performance Optimization (no linked issue)

Description:
This PR introduces micro-optimizations to BindableObject.OnBindingContextChanged() and related classes. The changes focus on improving performance when binding context changes frequently, particularly in CollectionView scenarios.

Key Changes:

  1. BindableObject: Remove Shell-specific attached property handling from base class
  2. Element: Avoid foreach when no logical children exist
  3. Page: Move Shell attached property handling here (from BindableObject)
  4. View/Span: Guard gesture recognizer propagation with count check

Platforms Affected:

  • All platforms (core framework changes)

Performance Impact:

  • Reduces overhead in BindingContext propagation
  • Avoids unnecessary iterations when collections are empty
  • Moves Shell-specific logic to appropriate subclass
📁 Files Changed
File Type Changes
src/Controls/src/Core/BindableObject.cs Fix -6 lines
src/Controls/src/Core/Element/Element.cs Fix +12/-4 lines
src/Controls/src/Core/Page/Page.cs Fix +6 lines
src/Controls/src/Core/Span.cs Fix +6/-1 lines
src/Controls/src/Core/View/View.cs Fix +6/-1 lines

Total: +30/-12 lines

💬 PR Discussion Summary

Key Comments:

  • dotnet-policy-service: Auto-assignment comment (standard)
  • kubaflo: Triggered CI run with /azp run

Reviewer Feedback:

  • No reviews yet

Disagreements to Investigate:

File:Line Reviewer Says Author Says Status
N/A N/A N/A N/A

Author Uncertainty:

  • None identified

Edge Cases to Check:

  • Shell BackButtonBehavior binding context when not on a Page
  • Shell SearchHandler binding context when not on a Page
  • Empty collections performance impact vs code complexity
  • Inheritance hierarchy - does moving logic to Page break any scenarios?
🧪 Tests

Status: ✅ COMPLETE

  • PR includes tests for performance optimizations (NO - performance change only)
  • Tests verify Shell attached properties still work on Page (ShellToolbarTests - 14 tests passed)
  • Tests verify BindingContext propagation still works correctly (93 BindableObject + 34 Element tests passed)

Existing Test Files:

  • src/Controls/tests/Core.UnitTests/ShellToolbarTests.cs
    • BackButtonBehaviorBindingContextPropagation() - Tests BackButtonBehavior inherits BC from Page ✅
    • BackButtonBehaviorBindingContextPropagationWithExistingBindingContext() - Tests BC propagation when already set ✅
  • src/Controls/tests/Core.UnitTests/BindableObjectUnitTests.cs - 93 tests ✅
  • src/Controls/tests/Core.UnitTests/ElementTests.cs - 34 tests ✅

Test Results:

  • ShellToolbarTests: 14 passed ✅
  • BindableObjectUnitTests: 93 passed ✅
  • ElementTests: 34 passed ✅

Note: This is a performance optimization PR. Existing unit tests verify behavior is unchanged.

🚦 Gate - Test Verification

Status: ✅ PASSED

  • Tests verify behavior is unchanged (ShellToolbarTests, BindableObjectUnitTests, ElementTests all pass)

Result: PASSED ✅

Performance optimization PRs don't have "before/after bug" tests. Instead, we verified:

  1. ✅ Existing unit tests still pass (confirms no behavioral regression)
    • ShellToolbarTests: 14 tests passed (including BackButtonBehavior BC propagation)
    • BindableObjectUnitTests: 93 tests passed
    • ElementTests: 34 tests passed
  2. ✅ Code changes are safe:
    • Shell attached properties moved from BindableObject to Page (correct, as they're only used on Pages)
    • Count guards added to avoid empty collection iteration (safe optimization)
    • All changes preserve existing behavior
🔧 Fix Candidates

Status: ✅ COMPLETE (Performance Optimization - No Alternatives Needed)

# Source Approach Test Result Files Changed Notes
PR PR #33460 Move Shell attached property handling from BindableObject to Page; add count guards to avoid empty collection iteration ✅ PASS (Gate) 5 files (+30/-12) Performance optimization - no bug to fix

Note: This is a performance optimization PR, not a bug fix. The try-fix skill is designed for bug fixes where tests fail/pass. For performance optimizations:

  • Tests don't fail without the changes (no bug)
  • Tests pass with the changes (no regression)
  • The optimization's value is in reduced overhead, not fixing broken behavior

Performance Analysis:

  1. BindableObject.OnBindingContextChanged() - Removed Shell property checks (ran on EVERY BindableObject)
  2. Page.OnBindingContextChanged() - Added Shell property checks (only runs on Pages)
  3. Element.OnBindingContextChanged() - Added count guard (avoids foreach on empty collections)
  4. View/Span.OnBindingContextChanged() - Added count guards (avoids foreach on empty gesture recognizers)

Rationale: Shell properties are only meaningful on Pages, so checking them on every BindableObject (including Labels, Buttons, etc.) is wasteful. Moving to Page is semantically correct AND faster.

Exhausted: N/A (Not applicable for performance optimization)
Selected Fix: PR's fix - Correct design (Shell properties belong on Page) with measurable performance improvement

@kubaflo kubaflo added the s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) label Jan 17, 2026
@rmarinho rmarinho merged commit 5ecf21a into dotnet:main Jan 19, 2026
162 of 167 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Feb 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants