Skip to content

[Flight] Walk parsed JSON instead of using reviver for parsing RSC payload #34

@AbanoubGhadban

Description

@AbanoubGhadban

Background

Backport of facebook/react#35776 — ~75% speedup in RSC chunk deserialization.

The react-server-dom-webpack package currently uses JSON.parse(json, reviver) to deserialize RSC payloads. The reviver callback is a major bottleneck: V8's JSON.parse is implemented in C++, and invoking a JS reviver callback for every key-value pair incurs ~4x overhead even with a no-op reviver.

Proposed change

Replace JSON.parse(json, reviver) with a two-step approach:

  1. JSON.parse(json) — runs entirely in V8's C++ engine, no callbacks
  2. reviveModel() — recursive pure-JS walk that applies RSC transformations

This needs to be applied across all runtime environments (browser, edge, Node.js).

Benchmark results (from upstream PR)

Payload Speedup
Small (142B) +72%
Medium (914B) +73%
Large (16.7KB) +75%
XL (25.7KB) +76%
Table (1000 rows, 110KB) +78%

Implementation approach

Rebuild react-server-dom-webpack from React fork rsc-patches/v19.0.3 with the optimization applied (fork PR).

Acceptance criteria

  • RSC payload parsing works correctly
  • Nested Suspense boundaries work
  • Client/server component mix works
  • Deserialization benchmarked on a real app

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions