You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When benchmarking vuejs/core#12349, we discovered that due to the way Vitest evaluates modules, there is a slight overhead on every access of import bindings, probably due to the fact that ssrTransform transforms exports into getters:
// a.jsexportleta=1// ---// b.jsimport{a}from'./a'// every access of `a` here has an getter overheadconsole.log(a)console.log(a)console.log(a)
However, for a library like Vue, the actual distributed file is bundled, so a will be scope-hoisted as a local variable in the same scope with the code in b.js, and has no getter overhead.
In hotpaths where a is accessed many times, this overhead can lead to misleading benchmark results. For example, it was confusing at first why instead of exporting a directly, nesting it under an object / namespace actually made it faster.
I'm not sure if there is an actual fix to this in Vitest - but at the very least we should document this caveat in the benchmark docs.
Describe the bug
When benchmarking vuejs/core#12349, we discovered that due to the way Vitest evaluates modules, there is a slight overhead on every access of import bindings, probably due to the fact that
ssrTransform
transforms exports into getters:export let a = 1
is transformed toHowever, for a library like Vue, the actual distributed file is bundled, so
a
will be scope-hoisted as a local variable in the same scope with the code inb.js
, and has no getter overhead.In hotpaths where
a
is accessed many times, this overhead can lead to misleading benchmark results. For example, it was confusing at first why instead of exportinga
directly, nesting it under an object / namespace actually made it faster.I'm not sure if there is an actual fix to this in Vitest - but at the very least we should document this caveat in the benchmark docs.
Reproduction
vuejs/core#12349 (comment)
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: