gitmyhub

R3

C# ★ 3.8k updated 1mo ago

The new future of dotnet/reactive and UniRx.

R3 is a reimplementation of Reactive Extensions (Rx) for C#, built by the same developer who created UniRx, a popular Rx library for the Unity game engine. Reactive Extensions is a programming pattern for handling streams of events over time, think button clicks, timers, or live data feeds, processed using a chain of operations. The original dotnet/reactive library has been around for many years, but its author believes several design decisions have not aged well, and R3 is the answer to those problems.

The core complaint with the old library centers on three things. First, when an error occurred in a pipeline, the original Rx would stop the entire subscription, which caused difficult-to-debug behavior in long-running apps like games or desktop software. R3 changes this: errors pass through a separate channel called OnErrorResume, and the subscription keeps running unless you explicitly choose to stop it. Second, the scheduling system (IScheduler) in the old library was a source of poor performance. R3 replaces it with the newer TimeProvider pattern built into modern .NET. Third, the old library used an interface design that allowed hidden contract violations; R3 uses abstract classes to fully control the subscription lifecycle.

A practical benefit of this redesign is that R3 tracks every active subscription. In apps with long lifecycles, such as games or GUI tools, it is easy to subscribe to an event and forget to clean it up. Accumulating thousands of these leaked subscriptions can quietly degrade performance. R3 makes all subscriptions visible so developers can spot and fix leaks.

Performance benchmarks shown in the README compare R3 against the original library and show meaningfully lower memory allocation and faster execution, particularly in scenarios where many subscriptions are created and destroyed. The library is distributed as a NuGet package, supports .NET Standard 2.0 and 2.1 as well as .NET 6, 7, and 8, and includes extra integration packages for Unity, Godot, Avalonia, WPF, WinForms, WinUI3, MAUI, MonoGame, Blazor, and several other platforms.

If you already know Rx, the API surface will feel familiar: you still create observables, chain operators with LINQ-style methods, and subscribe to results. The mental model carries over directly; only the internals and a few edge-case behaviors have changed. The full README is longer than what was shown.