Skip to content

Improve Performance for Arrays that are not extensible (and therefore not reactive) #6284

@fenduru

Description

@fenduru

Version

2.4.2

Reproduction link

https://jsfiddle.net/hgfx55h6/

Steps to reproduce

  1. Create large array (in my case this array contains more Arrays)
  2. Prevent extensions with Object.preventExtensions
  3. Set the array on a Vue viewmodel

What is expected?

Vue's reactivity system should not do anything with this array, and setting this property should have the same runtime as setting a string on the viewmodel (i.e. O(1) )

What is actually happening?

The dependArray function is invoked recursively on the object every time the array is accessed, causing the setting of that property to take linear time. This can occur many times per tick.


This reproducer is very close to my actual scenario. I am building a virtual grid, where I have a large source array, and I compute some start index (normally this would be based on scroll position, in this case I've just added a button to simulate scrolling), and the template renders these rows.

In this jsfiddle, I have Object.preventExtensions()'d the array and never change it. The only thing I am changing is the start index, however doing so has an enormous amount of lag. When I profile this I see:

image

My issue at its core has nothing to do with reactivity, and is solely about performance. This does not seem like something that should perform this poorly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions