Skip to content

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

Merged
merged 4 commits into from
Oct 18, 2019
Merged

perf(reactivity): optimize the performance of the canObserve #330

merged 4 commits into from
Oct 18, 2019

Conversation

edison1105
Copy link
Member

use the jsperf to test.
OS:Mac OS X 10.14.6

Chrome 77.0.3865

RE:31,462 ±2.59% 35% slower
Set:48,254 ±1.52% fastest

the test link https://jsperf.com/regandset

@@ -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(
Copy link
Contributor

@a631807682 a631807682 Oct 18, 2019

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)

Copy link
Member Author

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!

@laquasicinque
Copy link
Contributor

laquasicinque commented Oct 18, 2019

Surely Object would provide the biggest performance increase? https://jsperf.com/regandset/3

Edit: different perf test so that it always returns a boolean

@edison1105
Copy link
Member Author

edison1105 commented Oct 18, 2019

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.

@jacekkarczmarczyk
Copy link
Contributor

@laquasicinque why not just '[object Object]': true etc?

@laquasicinque
Copy link
Contributor

@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 true | false or else the response would be true | undefined even with me using true instead of 1. If you want short and true then !0 also works.

My example was really just trying to show that objects were faster (related to makeMap) and I was being lazy when I wrote the example code because js perf was breaking on me

@yyx990803 yyx990803 merged commit 60961ef into vuejs:master Oct 18, 2019
@vue-bot
Copy link
Contributor

vue-bot commented Oct 18, 2019

Hey @edison1105, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚

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.

7 participants