Repository navigation
feat(binding)!: take property paths as delegates so call sites build no expression tree - #549
Merged
Merged
Conversation
- Take each path selector as Func<TSource, TValue> in the binding stubs, the generated overloads and the interceptors. An expression tree parameter makes the compiler build the tree at every call site. - Keep Expression<Func<TSource, TValue>> on the Unsafe overloads, which read the tree by reflection. - Read a path written with ?. as the members it names. - Add RXUIBIND022 for a selector that is not a property path. - Mark selector lambdas static in the examples, tests and benchmarks. BREAKING CHANGE: the plain binding methods take Func<TSource, TValue>. Pass a stored expression to the Unsafe overload.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #549 +/- ##
==========================================
- Coverage 99.01% 99.01% -0.01%
==========================================
Files 471 472 +1
Lines 18864 18920 +56
Branches 2793 2813 +20
==========================================
+ Hits 18679 18734 +55
- Misses 185 186 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.



Summary
The binding methods take each property path as a delegate,
Func<TSource, TValue>, so a call site builds no expression tree.WhenChanged,WhenChanging,WhenAny,WhenAnyValue,WhenAnyObservable,BindOneWay,BindTwoWay,OneWayBind,Bind,BindTo,BindCommand,BindInteractionandInvokeCommandtake their path selectors asFunc. The generated overloads and interceptors match.Unsafeoverloads keepExpression<Func<TSource, TValue>>, because they read the tree by reflection.?..x => x.Child?.Nameis read as the pathChild.Name, the same asx => x.Child!.Name.?.ahead of a plain value.static.Why
An
Expression<Func<...>>parameter makes the compiler build the tree at the call site on every call, through reflection, even though generated code never reads the argument. A viewer that subscribes about a hundred paths on each tab switch spent most of that switch building trees it threw away. OnWhenChangedBenchmark's first observation the call drops from 3.49 us and 920 B to 1.25 us and 392 B on .NET 11, with the same result on .NET 10 and NativeAOT.Breaking changes
Func<TSource, TValue>where they tookExpression<Func<TSource, TValue>>. An inline lambda compiles as before. A stored expression no longer compiles against them: pass it to theUnsafeoverload, or write the lambda inline.Funcsignatures and does not match an older runtime's stubs.How this was verified
New tests cover the path reader, the
?.forms, each RXUIBIND022 reason, and a check of the compiled caller's IL that finds no call intoSystem.Linq.Expressions, with and without interceptors. The wholeReactiveUI.SourceGenerators.slnfbuilds and its tests run on Linux. The Uno filter was not built here because its Windows head needs MSBuild on Windows.Notes for the reviewer
ExtractorValidation.IsPropertySelectorandPathSyntax. A delegate type alone does not mark a path out from a result selector or a converter, so the stub's parameter name decides. A new stub's path parameters must pass that test.?.ahead of a plain value, as inx => x.Child?.Count, is not generated. It makes the lambda returnint?, which is not the member's type.ReactiveUI.Binding.Shared/Mixins, thePublicAPI.txtbaselines, the*.verified.cssnapshots, and thestaticmodifiers in examples, tests and benchmarks.Checklist