Skip to content

Improve TypedBinding performance with lazy handler initialization#32642

Closed
Copilot wants to merge 1 commit intodev/srozsival/binding-improvementsfrom
copilot/sub-pr-32382
Closed

Improve TypedBinding performance with lazy handler initialization#32642
Copilot wants to merge 1 commit intodev/srozsival/binding-improvementsfrom
copilot/sub-pr-32382

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 15, 2025

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!

Description of Change

Reduces compiled binding overhead by deferring property change handler evaluation until subscription time. Since compiled bindings are compiler-generated (from XAML {Binding ...} or C# .SetBinding(...)), we can optimize the internal implementation without affecting public API surface.

Key changes:

  • New constructor: Accepts handlersCount and handlers function instead of pre-built array, enabling lazy evaluation
  • Internal refactoring: Introduced IPropertyChangeHandler interface with two implementations:
    • LegacyPropertyChangeHandler: Maintains backward compatibility with existing constructor
    • PropertyChangeHandler: New implementation with deferred handler initialization
  • Optimized re-subscription: Skips unsubscribe/resubscribe when already bound to same object
  • Updated usage: Modified TemplatedItemsList to use new constructor pattern

Backward compatibility: Existing constructor remains functional via LegacyPropertyChangeHandler, allowing gradual migration.

Example (compiler-generated code pattern):

// Old pattern (eager evaluation)
var handlers = new Tuple<Func<Source, object>, string>[] { ... };
var binding = new TypedBinding<Source, string>(getter, setter, handlers);

// New pattern (lazy evaluation)
var binding = new TypedBinding<Source, string>(
    getter, 
    setter, 
    handlersCount: 2,
    handlers: source => new[] { 
        (source as INotifyPropertyChanged, "Property1"),
        (source.Child as INotifyPropertyChanged, "Property2")
    });

Issues Fixed

Performance optimization - no specific issue tracked.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Improve typed binding performance Improve TypedBinding performance with lazy handler initialization Nov 15, 2025
Copilot AI requested a review from simonrozsival November 15, 2025 08:13
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants