Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(server-renderer): optimize unrollBuffer by avoiding promises #11340

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

negezor
Copy link
Contributor

@negezor negezor commented Jul 12, 2024

Currently, unrollBuffer is an async function, which results in approximately a 10x slowdown in a mixed buffer and around a 1.5x slowdown in a synchronous buffer. Any Promise on the hot path is a performance killer.

In this PR, unrollBuffer will return a Promise only if a child buffer does; otherwise, it will always operate synchronously. However, even if a child buffer returns a Promise, we can continue to operate synchronously if further nesting is not required for another child buffer.

Of course, there are other functions where something similar happens, such as renderComponentVNode, but this requires separate consideration.

Performance was tested on the following hardware:
CPU: AMD Ryzen 7950x3D
System: WSL 2 Arch Linux on Windows 11
Node.js: v22.4.0

Before

 ✓ packages/server-renderer/__tests__/unrollBuffer.bench.ts (2) 1820ms
   ✓ unrollBuffer (2) 1819ms
     name             hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · sync   3,526,611.07  0.0002  0.3646  0.0003  0.0003  0.0005  0.0006  0.0009  ±0.59%  1763307   fastest
   · mixed    303,890.63  0.0028  0.4434  0.0033  0.0032  0.0049  0.0055  0.0233  ±0.77%   151946

After

 ✓ packages/server-renderer/__tests__/unrollBuffer.bench.ts (2) 2321ms
   ✓ unrollBuffer (2) 2320ms
     name             hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · sync   5,118,319.85  0.0002  0.0730  0.0002  0.0002  0.0002  0.0003  0.0005  ±0.11%  2559160   fastest
   · mixed  3,301,545.89  0.0003  0.2527  0.0003  0.0003  0.0005  0.0006  0.0009  ±0.48%  1650773

Copy link

github-actions bot commented Jul 12, 2024

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 89.5 kB 34.2 kB 30.9 kB
vue.global.prod.js 146 kB 53.6 kB 47.8 kB

Usages

Name Size Gzip Brotli
createApp 51.4 kB 20.1 kB 18.3 kB
createSSRApp 54.7 kB 21.5 kB 19.5 kB
defineCustomElement 53.7 kB 20.9 kB 19 kB
overall 65.1 kB 25.2 kB 22.7 kB

@yyx990803
Copy link
Member

Tested this in https://github.com/eknkc/ssr-benchmark with renderToString and it got 20% faster, great job!

@yyx990803 yyx990803 merged commit 05779a7 into vuejs:main Jul 12, 2024
11 checks passed
@negezor negezor deleted the optimize-unroll-buffer branch July 15, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants