-
-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/stateless filtering and transforming #823
Feature/stateless filtering and transforming #823
Conversation
I'm in favor of these additions, but I do have a small issue with the names. These are going to require some documentation to ensure that the provided filter/transform functions are completely deterministic and very efficient because they'll be invoked more times than one might expect. |
I'm not sold on the names, either. Other options include Regarding documentation, is the documentation I already added insufficient for you? |
Agreed... Although Intellisense finds anything with "Filter" in the name, the things starting with "Filter" are shown first. So... No Of the remaining choices, I like
I feel like it might be better to get the opinions of someone who isn't familiar with DD to find a name that people can know what it does intuitively. My intuition is ruined by familiarity. Maybe we could take a survey in the Rx slack?
Yes, your documentslation is fine... Great, actually, but the not everyone will see the XML comments, so a Wiki article might also be helpful. |
In a perfect world, I'd say it should be
I can get behind that. |
Of the names we've examined so far, my favorite is |
Maybe your PR title has the right of it... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been sat on this for a while so I could think long and hard about it and I think using optimiser options (see my comments against the code) could be a good solution.
The only draw back would be yet more optional overloads, unless of course we introduce an overload which accepts the transform / filter functions + a record containing all the additional options. This would be similar to my suggestion on #819 and also similar to the new binding options.
|
||
namespace DynamicData.Cache.Internal; | ||
|
||
internal sealed class TransformByValues<TDestination, TSource, TKey> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the same a Convert?
Maybe that could be resurrected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhhh, yep, that looks pretty much the same, save for a few technical optimizations.
I think it's worth considering that .Convert()
has a bit of a discoverability problem, then. So, we could consider options for addressing that:
- Add
TransformByValues()
(or whatever name we agree on) anyway, and have it and.Convert()
both call the same implementation behind the scenes. - Option 1 but also mark
.Convert()
as Obsolete, to be removed some day. - Just try and address it with some new Wiki content, as Darrin already suggested. In which case, I would still swap
.Convert()
over to the implementation I wrote here.
/// <param name="source">The source stream of collection items to be transformed.</param> | ||
/// <param name="transformFactory">The transformation to be applied to each item.</param> | ||
/// <returns>A stream of collection changesets where upstream collection items are transformed by the given factory function.</returns> | ||
public static IObservable<IChangeSet<TDestination, TKey>> TransformByValues<TDestination, TSource, TKey>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether we can achieve this overload using an optimizer. For example Sort accepts SortOptimisations which amongst other options allows the consumer to specify SortOptimisations.ComparesImmutableValuesOnly.
If something similar was used for Transform, or for Filter we could use different code paths in the background and eliminate the need to new named overloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could probably get behind that, in theory, but part of the problem is that this optimization is ONLY applicable for certain scenarios of filtering and transforming. Like, any of the overloads that take IObservable<>
of something to control filtering flat-out cannot use this optimization.
So, as an example, if we were to define FilterOptimizations.DontCacheItems
, we'd have to do one of a few things:
- Only define one overload to take a
FilterOptimizations
paramter, the one where the filter predicate is justFunc<T, bool>
. With this, if we ever wanted to add more optimizations for other overloads, we'd have to write SEPARATE enums for those overloads. - Throw an exception if you try and specify
FilterOptimizations.DontCacheItems
with an overload that supports dynamic filtering, E.G.IObservable<Func<T, bool>>
. - Just silently have
FilterOptimizations.DontCacheItems
do nothing for overloads that support dynamic filtering, leading users to think they're getting a performance boost when they're not.
On a separate note (and this comes with a grain of salt, because I have not done a DEEP dive into it, just seen it on the surface) my current impression of how sorting works in DynamicData is that I don't really like it. I don't like how much seemingly-unnecessary stuff there is inside ISortedChangeSet<>
, and SortOptimizations
is part of that. I have found that the "extra" stuff in ISortedChangeSet<>
makes it impossible to implement some of the most common querying scenarios supported by LINQ. All that being said, I'm initially very wary about the idea of adding FilterOptimizations
in the same manner as SortOptimizations
.
@JakenVeina regarding naming just go with your gut - dealers choice One more suggestion however is maybe FilterImmutable / TransformImmutable after all there is a GroupByImmutable which although has a slightly different behaviour it may provide consistency. Let me know when this is ready and let's merge. |
If And my gut says |
I can deal with the |
…nsformManyAsyncFixture
…ed as method parameters.
…ls to .Benchmarks, to match the other two.
…to provide better performance for static/deterministic scenarios.
0367828
to
d1e9859
Compare
@RolandPheasant I've updated namings, as discussed, and re-wrote the documentation, after some feedback from @Insire. Since the older We should be good for a merge. |
I'm quite happy with the new xml comments, which was a major point of discussion i had with @JakenVeina |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Implemented one of the operators described in #758 as well as an equivalent transform operator.
Also made a few housekeeping changes, but I've split those out into separate commits, so they can more-easily be reviewed and/or excluded if others don't agree.
Benchmark results, highlighting the performance of the new operators, versus existing ones: