denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.05k stars 5.23k forks source link

perf: react 18.3 really slow in Deno compared to 18.2 #20510

Open lino-levan opened 1 year ago

lino-levan commented 1 year ago

Given this benchmark: https://github.com/oven-sh/bun/blob/main/bench/react-hello-world/react-hello-world.deno.jsx

Do the following change:

-import { renderToReadableStream } from "https://esm.run/react-dom/server";
-import * as React from "https://esm.run/react";
+import { renderToReadableStream } from "https://esm.run/react-dom@next/server";
+import * as React from "https://esm.run/react@next";

and see the comparison. The performance seems to be really bad. Originally reported by @190n.

image

Any ideas @littledivy?

190n commented 1 year ago

More data, using multiple React versions on the other runtimes too. With the upgrade, Bun gets much faster, Node gets barely faster, and Deno becomes extremely slow. I kept the versions of react and react-dom in sync although from testing with Deno it seems like the significant performance drop is due to react-dom (i.e. react 18.3 + react-dom 18.2 performs fine).

Runtime Req/s (React 18.2) Req/s (React 18.3)
Bun 49237 62326
Node 18506 19116
Deno 43228 2967

Req_s (React 18 2) and Req_s (React 18 3)

Hardware: Framework 13, Intel i5-1240p, 8+16GB DDR4-3200MHz OS: Arch Linux Runtimes: Node 20.6.1, Deno 1.36.4, Bun 1.0.1 react/react-dom: latest npm version (18.2.0) or latest next version (18.3.0-canary-d6dcad6a8-20230914) (I changed esm.run URLs for Deno as @lino-levan shows, and I changed package.json for Node and Bun). Test process: run one of the scripts in the appropriate runtime, and then run bombardier localhost:<port> -d 5s in another terminal.

littledivy commented 1 year ago

I don't know if this is the case here but I've seen varying performance when using react from esm.sh. So maybe this could be a bug in esm.sh? Anyways, a better way to know would be to use same react (probably vendored) for all runtimes.