NetFabric / LinqBenchmarks

Benchmarking LINQ and alternative implementations
MIT License
174 stars 14 forks source link

Cister.ValueLinq benchmarks for ToArray/ToList #8

Closed manofstick closed 3 years ago

manofstick commented 4 years ago

I have put these into a partial class, as easier to control given that this is meant as as "replacement" for System.Linq (i.e. you would drag one or the other namespace via a using, rather than both).

Also, as Cistern.ValueLinq is fully composable I have given a number of different methods for how to do each problem, which ends up as a bit of a combinatorial explosion, but also another reason why doing it in the partial class makes sense.

The "standard" version (i.e. ToList()/ToArray() with no arguments) are supposed to mirror System.Linq as much as possible, i.e. they won't using pooling, but you can specify some arguments which nudges them in various directions (but the logic is a bit convoluted, as they try to be "smart"). There are To(Array|List)(ViaPool|ViaStack) to force a particular style.

Another axis of freedom is standard delegates (Func<,>) or value based IFunc<,>. Both of these have value-type and reference-type arguments.

And yet another axis of freedom, where List is the source, is if you want to access it via Index or via it's List<>.Enumerator. By default it once again follows System.Linq in that it uses the Enumerator, but you can force it by using OfListByIndex. Once again there are some "smarts" in place here, because although System.Linq does it by Enumerator, it also has some optimizations on ToArray/ToList which doesn't. Which makes it a bit hard to fully replicate it's functionality, but if the source is originally an IEnumerable<> rather than a List then if it's iterator in foreach it uses the Enumerator but if it passes through to an Aggregation function then it uses the index version (basically).

Which is the final degree of freedom which is offered in the array pool version where you can act either in pull mode (ie, through similar mechanism to IEnumerator) or a push mode (where the actions are inverted).

Anyway, it means that you have lots of choices to choose from, but I have tried to make the simplist (i.e. the one where your code looks exactly the same as System.Linqs) a reasonable default choice.

In the broader context, I think I'm fairly happy with overall architecture now of Cistern.ValueLinq, so now I just have to fill in all the details! Next step is to pull over the SIMD Vector stuff that I'd done in Cistern.Linq :-) And hopefully get around to filling in the rest of the System.Linq API sooner rather than later. But think I'm pretty close to burnout after this initial sprint to this junction!

aalmada commented 3 years ago

@manofstick Sorry that I took so long to catch up with this. I took some time away from OSS. The partial class is a great idea. I may extend it to the other libraries. I hope to merge this soon and then publish the results.

aalmada commented 3 years ago

I merged it. I then tried to upgrade to the latest version but I can't figure out what changed.

manofstick commented 3 years ago

@aalmada

I dropped everything other than .net 5 support to make it easier to manage, so that is probably the issue.

Hmmm. But yeah, I'm not sure if I'm planning on continuing with ValueLinq; I've tried getting a number of people interested in it in some way, but to no avail (actually you were one of those people, which I guess this has slightly changed the equation, but...).

aalmada commented 3 years ago

@manofstick

I noticed you dropped all platforms other than .NET 5.0 but that's not the issue. Did you drop support for IInFunc<>? image

I've been working on NetFabric for two years with lots of package downloads but no help. Not even a single comment on how to improve something...

manofstick commented 3 years ago

@aalmada

OK; made a pull request where I removed those items.

I've been working on NetFabric for two years with lots of package downloads but no help. Not even a single comment on how to improve something...

Ha; I don't think I got any real package downloads - I'm pretty sure they were all just automated package analysers for me! Then again I didn't spend much time spruiking it, but there were a few people to whom I thought would be at least somewhat interested by my novel architectural design... Meh, c'est la vie.

Anyway, maybe I'll become inspired again. But as I'm doing it in my "spare" time, it's a bit hard. I possibly have some ideas about integrating it indirectly into a mini dynamic language I have at work, so that might see me become work on it again!!

Hopefully it might provide some inspiration to you...