-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
perf(reactivity): optimize the performance of the canObserve
#330
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
Conversation
packages/reactivity/src/reactive.ts
Outdated
@@ -27,13 +27,17 @@ const readonlyValues = new WeakSet<any>() | |||
const nonReactiveValues = new WeakSet<any>() | |||
|
|||
const collectionTypes = new Set<Function>([Set, Map, WeakMap, WeakSet]) | |||
const observableValueRE = /^\[object (?:Object|Array|Map|Set|WeakMap|WeakSet)\]$/ | |||
const observableTypes = new Set<String>( | |||
['Object', 'Array', 'Map', 'Set', 'WeakMap', 'WeakSet'].map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you should use makeMap
instead
see #275 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you should use
makeMap
instead
see #275 (comment)
good suggestion!
Surely Object would provide the biggest performance increase? https://jsperf.com/regandset/3 Edit: different perf test so that it always returns a boolean |
@laquasicinque thanks for your suggestion. |
@laquasicinque why not just |
@jacekkarczmarczyk Only really because its fewer characters and the result is more or less the same. I'm casting to Boolean anyway which would get My example was really just trying to show that objects were faster (related to |
Hey @edison1105, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚 |
use the
jsperf
to test.OS:
Mac OS X 10.14.6
Chrome 77.0.3865
the test link https://jsperf.com/regandset