How RxJS Was Refactored to Be Smaller and Faster – Insights from D2 Session

The D2 Language & Framework session covered Ben Lesh’s RxJS refactoring to reduce bundle size and boost speed, Ujjwal’s deep dive into ES2020/2021 features, monadic lift functions versus optional chaining, and practical performance gains achievable by targeting modern JavaScript standards.

Alibaba Terminal Technology
Alibaba Terminal Technology
Alibaba Terminal Technology
How RxJS Was Refactored to Be Smaller and Faster – Insights from D2 Session

The D2 Language & Framework session featured RxJS maintainer Ben Lesh demonstrating how the library was refactored to become smaller and faster, and Igalia engineer Ujjwal presenting the latest developments in ES2020, ES2021, and upcoming TC39 proposals such as Error Cause (Stage 2) and Async Context (Stage 0).

Refactoring RxJS Architecture: Making It Smaller and Faster – Ben Lesh

Q: Which tool shows the bundle size structure?

A: source-map-explorer /

webpack-bundle-analyzer

Q: What does RxJS do?

A: It is a Reactive JavaScript library. More details at rxjs.dev (English) and cn.rx.js.org (Chinese).

Q: Does refactoring make the code less readable?

A: Potentially, but changes are localized, documented, and covered by comprehensive unit tests, so readability remains manageable.

Q: Which is more valuable, architectural refactoring or code‑level refactoring?

A: It depends on the scenario; frameworks benefit more from code‑level improvements, while rapidly evolving products may need architectural changes.

Unveiling TC39: ES2020 and ES2021 – Ujjwal

Ben’s lift Function vs. Optional Chaining

The lift function originates from functional programming’s Monad concept.

Monads are abstract data types used to represent computations instead of data, enabling the organization of ordered operations and defining control flow without side effects. – Wikipedia

In JavaScript, values are mutable, so we wrap them with a Functor to achieve immutability. When values are nested, a Monad can “probe” through layers to extract the underlying value.

const safeFindObject = R.curry((db, id) =>
  Maybe.fromNullable(find(db, id)); // Monad provides safety

We can lift unsafe functions into a Monad:

const lift = R.curry((f, value) =>
  Maybe.fromNullable(value).map(f);
const safeFindObject = R.compose(lift, find); // lift makes find safe

Optional Chaining (ES2020) offers a concise syntax for accessing nested properties without explicit monadic handling:

const obj = {};
let nestedProp = obj.first?.second; // ES2020 optional chaining
R.prop('second', R.prop('first', obj)); // functional style using Maybe‑like behavior

Browser support for Optional Chaining is already high (≈85% overall, 100% on modern browsers). Tools like caniuse.com confirm this.

Targeting modern JavaScript (e.g., ES2017) can yield significant performance gains. For example, compiling a site to ES2017 can reduce bundle size by ~545 KB and improve execution speed, as demonstrated by the estimator tool estimator.dev .

Since ES2015 (ES6), JavaScript has adopted classes and block‑scoped variables, aligning it with mainstream languages. Today, most browsers fully support ES2017, and many projects already use TypeScript to leverage these modern features.

JavaScript’s success stems from its universal adoption, strong governance by the TC39 committee, and continuous evolution toward higher performance and better standards.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceJavaScriptrxjsrefactoringES2020Monads
Alibaba Terminal Technology
Written by

Alibaba Terminal Technology

Official public account of Alibaba Terminal

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.