2 ms·
I was pretty surprised at how my large Vue 2 form ground to a halt when I used it with 1-2 thousand objects. Mostly via many layers deep of small nested JSON ob
by dmix 7y ago
I was pretty surprised at how my large Vue 2 form ground to a halt when I used it with 1-2 thousand objects. Mostly via many layers deep of small nested JSON objects which grow exponentially really fast ... because customers like jamming as much data as possible into a single HTML page's form instead of breaking it up across multiple forms/parent objects like we intended.
Beyond work-arounds like pagination/hiding data, I've found the best solution is being careful with what data is marked as Observable/reactive and tracked by Vue for changes...which in Vue 2 is the automatic default behaviour where everything put it into data()/computed/Vuex or elsewhere is monitored. Then on top of that functionality which updates tons of rows at once (for example drag and dropping a row which then updates { order: n } for a hundred objects) then resulted in mini-freezes/slow downs.
Crawling through dev tools memory captures never helped much because Vue is already extremely async/concurrent, so there was never one big slow thing to refactor - the problem was many thousands of small things that turned into one big slow thing.
Vue 3 (surprisingly) helped me solve this problem, not by adding some extra concurrency to the view layer, but by making all the data default to a simple JS module, instead of a big options interface in Vue 2 where everything in Observable by default, and instead you explicitly mark which stuff should be reactive and watched. I managed to reduce the number of observed objects by 50-75% in some cases which got rid of any slow-downs.
This of course was a rare use-case and not a knock on Vue, most people aren't managing hundreds of objects in a single HTML UI/form but it also wasn't very extreme either - just a modern web-based data-heavy B2B software requirement.
Not all of it is do to the inherent framework design either but about how you use it + having good best-practices and defaults.
I'm sure there was ways to do the same in Vue 2 but being the default approach significantly helps organize the code in a performant way. Only the data which needs to be reactive will be reactive and everything else is simple fast JS objects.
- honopu 7y agoUse object.freeze in your mutation.
- dmix 7y agoYeah that was what I was started doing initially before switching to Vue 3. It gets aesthetically ugly pretty fast when every time you declare a variable (or more importantly flagging subsections of bigger objects) you have to put Object.freeze in front of it x100. And make sure any data inserted indirectly into an object afterwards gets frozen as well. I'd much rather the default be non-observed and the reactive data is explicitly marked, instead of the opposite. Which is a surprisingly under-reported evolution in Vue 3.
- earthboundkid 7y agoFreeze doesn’t play nicely with Vue, in my experience.