Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

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

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.

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.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Report an issue with this article
PerformanceJavaScriptrxjsrefactoringES2020Monads

Reader feedback

Was this useful?

Useful0

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion