Comments (10)
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.
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.
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.
I think you'll notice that I do this for writing to a channel as well.
from open.channelextensions.
I'm quite willing to change this. Would you look at the write version of this and tell me what you think there?
Open.ChannelExtensions/Open.ChannelExtensions/Extensions.Write.cs
Lines 41 to 51 in fcba7ca
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.
This has been corrected as per your suggestion.
https://www.nuget.org/packages/Open.ChannelExtensions/6.0.1
from open.channelextensions.
@azhmur Thank you for pointing this out. :)
from open.channelextensions.
Thank you for fast and reasonable response. Great library, I wish this would be part of System.IO.Pipelines.
from open.channelextensions.
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.
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)
- Support disposable messages HOT 9
- Can we state a gradual thread increment strategy in variable max_concurrency ? HOT 1
- Ambiguous ReadAllConcurrentlyAsync signatures, when using named arguments HOT 5
- Update System.Threading.Channels HOT 2
- Batching with time limit to force data through on an interval HOT 16
- Different/Incorrect Behaviour in .NET Framework HOT 9
- IntelliSense not showing in VisualStudio HOT 4
- BatchingChannelReader Timer ObjectDisposedException HOT 3
- Exception handling in pipeline HOT 14
- Channels created by `Source` or `ToChannel` do not reach completion when canceled. HOT 4
- Test involving a BatchingChannelReader with 'WithTimeout' integration keeps failing HOT 5
- Multi channel multi transformation - how to do it using ChannelExtensions HOT 3
- ReadAllConcurrently completes before last task completes HOT 1
- Unbatch / Split HOT 3
- Exception handling HOT 4
- Supporting .Net 6 and up HOT 2
- Conditional package reference to System.Threading.Channels NuGet HOT 4
- IAsyncEnumerable ToChannel Extension not visible in .NET 8 projects HOT 3
- Question: Exception in Pipe breaks the channel? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from open.channelextensions.