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: use new Empty() instead of Object.create(null) for performance #12172

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

c0dedance
Copy link

Optimization: Use new Empty() instead of Object.create(null) for performance
v8 has a better optimization for initializing functions compared to Object

Copy link

netlify bot commented Oct 14, 2024

Deploy Preview for vue-sfc-playground failed.

Name Link
🔨 Latest commit 92a4185
🔍 Latest deploy log https://app.netlify.com/sites/vue-sfc-playground/deploys/670cc814856c6400084ad357

Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB (-268 B) 38 kB (-3 B) 34.2 kB (+6 B)
vue.global.prod.js 159 kB (-317 B) 57.9 kB (-18 B) 51.4 kB (-17 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.8 kB (-129 B) 18.3 kB (-28 B) 16.7 kB (-24 B)
createApp 54.8 kB (-215 B) 21.3 kB (-22 B) 19.4 kB (+1 B)
createSSRApp 58.8 kB (-216 B) 23 kB (-31 B) 20.9 kB (-30 B)
defineCustomElement 59.5 kB (-246 B) 22.8 kB (-29 B) 20.8 kB (-51 B)
overall 68.4 kB (-246 B) 26.3 kB (-35 B) 23.9 kB (-47 B)

Copy link

pkg-pr-new bot commented Oct 14, 2024

Open in Stackblitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@12172

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@12172

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@12172

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@12172

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@12172

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@12172

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@12172

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@12172

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@12172

vue

pnpm add https://pkg.pr.new/vue@12172

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@12172

commit: 92a4185

@edison1105
Copy link
Member

It would be best to provide a benchmark to demonstrate that there is indeed a performance improvement. If the performance improvement is significant, then this PR is worthwhile.

@edison1105 edison1105 added the need more info Further information is requested label Oct 14, 2024
@c0dedance
Copy link
Author

It would be best to provide a benchmark to demonstrate that there is indeed a performance improvement. If the performance improvement is significant, then this PR is worthwhile.

benchmark: jsbenchmark

@c0dedance c0dedance marked this pull request as ready for review October 14, 2024 07:28
@ferferga
Copy link
Contributor

This isn't the case here:
image

Edge 129.0.2792.89 on Windows 11

@Smrtnyk
Copy link

Smrtnyk commented Oct 15, 2024

benchempty
if it means something, this is how it looks on my machine on chrome 129

@jacekkarczmarczyk
Copy link
Contributor

I'm getting similiar results to @Smrtnyk 's one on Edge 129/Chrome 129, but on Firefox both approaches give similar performance

@edison1105
Copy link
Member

Object.create(null) does not appear on the hot path. I think this change may not significantly improve performance.

@edison1105 edison1105 added need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. and removed need more info Further information is requested labels Oct 15, 2024
@ferferga
Copy link
Contributor

@Smrtnyk I can replicate your results in Chrome as well. I believe it's because the difference in V8 versions (Edge has V8 12.9.17.8 and Chrome V8 12.9.202.27)

In either case, I also agree with Edison that this might be premature optimization, because this could easily change in a new JS engine version, I opened a similar issue at sindresorhus/eslint-plugin-unicorn#2455 and to some degree I agree with sindresorhus.

Either way, I think it's a good refactor to move the creation logic into shared and import from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants