Useful extension?

13 views
Skip to first unread message

Fil Mackay

unread,
Aug 11, 2011, 2:47:18 AM8/11/11
to Disruptor-net
Is this a useful extension?


public static class ProducerBarrierExtensions
{
public static void NextEntry<T>(this IProducerBarrier<T>
producerBarrier, Action<T> action)
where T : class
{
T data;
var sequence = producerBarrier.NextEntry(out data);
action(data);
producerBarrier.Commit(sequence);
}
}

usage:

producer.NextEntry(entry =>
{
// set the entry values
entry.Value = 1;
});

Olivier Deheurles

unread,
Aug 11, 2011, 10:53:30 AM8/11/11
to disrup...@googlegroups.com
Sounds like a good idea but first thing that come to my mind is that the Action will probably endup beeing used with a closure to some external state. If this state is different on each call to the action, you endup allocating the class generated by the compiler each time.

You should try to write a perf test but I would not be surpised to see the allocations triggering lots of GCs and impacting significantly perfs ;)

LinQ bring a lot of very nice syntactic sugar to .NET but it needs to be used very carefully, a single source of allocation on hot path code can have massive impacts ;)

Olivier

Fil Mackay

unread,
Aug 12, 2011, 9:22:39 PM8/12/11
to disrup...@googlegroups.com
Great points Oliver!

I'll do some testing on it but yes I think you are right. Implementing
IObserver going to suffer the same fate? I'll reflect through some
samples on my mutation...

Olivier Deheurles

unread,
Aug 13, 2011, 9:02:48 AM8/13/11
to disrup...@googlegroups.com
RX queries are generally OK but as soon as you introduce side effects, on closures for instance, you can get serious perf degradations.

There are 2 challenges with RX:
- big mind shift to move to a push model
- a lot happens under the hood and as long as you don't understand what is happening, you run the risk of massive performance hits.

Olivier

Reply all
Reply to author
Forward
0 new messages