Question

In the ReactiveExtensions source code there are huge swathes of codes switching between different implementations such as

https://github.com/Reactive-Extensions/Rx.NET/blob/master/Rx.NET/Source/System.Reactive.Linq/Reactive/Linq/QueryLanguage.StandardSequenceOperators.cs

and a snippet

#if !NO_PERF
    return new Distinct<TSource, TSource>(source, x => x, EqualityComparer<TSource>.Default);
#else
     return Distinct_(source, x => x, EqualityComparer<TSource>.Default);
#endif

what is the intention of this flag NO_PERF and what is the difference in behaviour between the library compiled with it and without it.

Was it helpful?

Solution

As a member of the Rx team, I can answer this:

The answer goes back to our changes from Rx 1.1 to Rx 2.0. We wanted the ability to keep the old style of using AnonymouseObservable around just in case, but for most of the time, you want the performance enhanced version.

There are big differences in both performance, and in some cases more eager disposal. You can find out more information about our changes here.

OTHER TIPS

It's used to switch in/out logic that favours safety over performance. For example, in most of the operator implementations an AnonymousObservable is created to wrap OnXXX invocations and catch exceptions in observers.

When !NO_PERF is true this wrapper is not created - this shortens the call chain for queries and results in less objects, less GC pressure and faster code - but it's less safe as it assumes well-behaved observers.

This code has lots of examples.

I don't know, but I can see it being used inside other MS code that is a client of Rx, understands the consequences and is prepared to take on the responsibility of creating well-behaved clients.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top