Giter Club home page Giter Club logo

Comments (10)

electricessence avatar electricessence commented on May 20, 2024

I picked up this technique from chatting Ben Adams on a project I published. It's an optimization that he had presented to me. It's not something you would consider always doing, but in this case the "pre-fetch" seemed a logical step as you are more likely to saturate threads this way.

If you don't think this is appropriate, I could introduce a parameter to allow for disabling it.
At the moment, I can't think of any reason you wouldn't want the optimization.

from open.channelextensions.

electricessence avatar electricessence commented on May 20, 2024

ends up in blocking at the end of channel

Not sure what you're suggesting here.
If you have a bounded channel, and it reaches it's configured limit of (lets say) 100. Then you really have 101.
In other cases, where you are either unbound or the channel is not full, you're simply preemptively acquiring an item.

from open.channelextensions.

electricessence avatar electricessence commented on May 20, 2024

All that said, I can see where this micro-optimization may not apply to Channels the same way it might in other situations.
It's meant for cases where you expect some amount of potential async delay and .TryRead there really is none.

from open.channelextensions.

electricessence avatar electricessence commented on May 20, 2024

I think you'll notice that I do this for writing to a channel as well.

from open.channelextensions.

electricessence avatar electricessence commented on May 20, 2024

I'm quite willing to change this. Would you look at the write version of this and tell me what you think there?

long count = 0;
var next = new ValueTask();
foreach (ValueTask<T> e in source)
{
T? value = await e.ConfigureAwait(false);
await next.ConfigureAwait(false);
count++;
next = target.WriteAsync(value, cancellationToken);
}
await next.ConfigureAwait(false);
return count;

I think in the case of writing from an enumerable, the enumerable can be yielding longer than it takes for the next opening in the channel to occur. So there is some value there.
But I think you're right about the read operation. I can't foresee how it can benefit.

from open.channelextensions.

electricessence avatar electricessence commented on May 20, 2024

This has been corrected as per your suggestion.
https://www.nuget.org/packages/Open.ChannelExtensions/6.0.1

https://github.com/Open-NET-Libraries/Open.ChannelExtensions/blob/master/Open.ChannelExtensions/Extensions.Read.cs#L100-L105

from open.channelextensions.

electricessence avatar electricessence commented on May 20, 2024

@azhmur Thank you for pointing this out. :)

from open.channelextensions.

azhmur avatar azhmur commented on May 20, 2024

Thank you for fast and reasonable response. Great library, I wish this would be part of System.IO.Pipelines.

from open.channelextensions.

electricessence avatar electricessence commented on May 20, 2024

I wish this would be part of System.IO.Pipelines.

@azhmur Yeah, there are a large number of extensions I wish were simply built into the ecosystem.
Check out my database extensions library.
https://github.com/Open-NET-Libraries/Open.Database.Extensions (there's even a package for channels)
In either case, a large number of basic operations could be streamlined. I couldn't just sit by and not have best practices built in.

from open.channelextensions.

electricessence avatar electricessence commented on May 20, 2024

Thank you for fast and reasonable response.

@azhmur I love that someone took the time to scrutinize the code and post an issue. As I mentioned, I do think there is some amount of reasonable optimization for that pattern under specific cases, but this was not the case. I hadn't thought about it so deeply before. Thanks again.

from open.channelextensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.