Skip to content

Seroval draws performance down on large payloads #7719

Description

@kompot

Which project does this relate to?

Router

Describe the bug

We've found that using default seroval serialization for our @tanstack/react-router-ssr-query backed SSR app leads to pretty significant performance penalties on large payloads.

We have big (8mb uncompressed JSON) catalog of items that is:

  • cached in SSR workers, used to reduce it to a pretty small HTML output on initial request
  • streams catalog of items in JSON when HTML/CSS is already being processed

This way we get best of both worlds: no extra request client side and pretty fast LCP as JSON to hydrate is streamed.

But we've found that using default transport gives us around 50% performance penalty. In a real world production app with this 8mb streamed catalog we get ~24rps and ~180ms avg latency (4 node workers, autocannon it locally, all API data is cached). With a hacked transport (where we've replaced seroval with JSON.stringify) — ~36rps and ~120ms avg latency.

To confirm the point I've created a repo (https://github.com/kompot/seroval-vs-jsonstringify) that has a benchmark of seroval vs JSON.stringify and gives kind of the same numbers. 10mb serialization on a fast machine takes 70ms in seroval and 7ms with JSON.stringify

Complete minimal reproducer

https://github.com/kompot/seroval-vs-jsonstringify

Steps to Reproduce the Bug

Run a test, confirm a point that seroval leads to performance penalties even on small payloads.

Expected behavior

I would suggest an option to opt out of seroval in @tanstack/react-router-ssr-query at least for payload body. I guess that 99+% of payloads in real worlds apps are plain JSON does not need to fight problems seroval was created for — serialize any JS object.

Screenshots or Videos

No response

Platform

  • Router / Start Version: @tanstack/react-start@1.168.25, @tanstack/react-router@1.170.15, @tanstack/router-core@1.171.13
  • OS: macOS/Linux
  • Browser: n/a
  • Browser Version: n/a
  • Bundler: vite
  • Bundler Version: 8.0.x

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions