Replies: 1 comment 1 reply
-
I think this would be better. const __sfc__ = {
__name: 'App',
props: { a: String },
setup(__props) {
return (_ctx, _cache) => {
return (_openBlock(), _createElementBlock("div", {
title: __props.a,
+ class: _cache._hoisted_2 || (_cache._hoisted_2 = _normalizeClass({ red: ctx.foo, blue: true, green: false }))
}, null, 8 /* PROPS */, _hoisted_1))
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is a proposed optimization to the Vue compiler
What?
I suggest that Vue compiler should detect if a bound value is a constant (i.e. an array or an object literals whose values are themselves only constants) and hoist those values into const variables.
For instance, consider this template:
Here's the current and suggested compiled render functions:
This shouldn't require a lot of work, as analyzing bindings for "const-ness" is already performed by Vue compiler to support hoisting elements. Remove the
title
binding in this example and the wholediv
is hoisted!Why?
For perf, of course.
This has two benefits:
When?
This can be more common than you'd think, for example:
motion-v
library is using complex props that are constant object literals 90% of the time.And in my experience I see almost nobody "manually" hoisting theses options into setup constants, i.e. writing:
Beta Was this translation helpful? Give feedback.
All reactions