-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
perf(VDataTable): reduce reactivity overhead for immutable items #19257
base: master
Are you sure you want to change the base?
Conversation
@@ -62,6 +62,11 @@ export function transformItems ( | |||
items: DataTableItemProps['items'], | |||
columns: InternalDataTableHeader[] | |||
): DataTableItem[] { | |||
if (isReadonly(items)) { | |||
items = items.map(item => toRaw(item)) |
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.
Comment it out, same performance.
This line seems has no impact on prevent reactivity overhead as per testing.
Looks like shallowReadonly
removes element's reactivity already demo
Very cool PR Since Other props in <template>
<v-app>
<v-container>
<v-text-field v-model="search" />
<v-btn
@click="selectableProp = 'disabled'"
>change selectable Prop to disabled</v-btn>
<v-data-table
:headers="headers"
:items="virtualBoats"
:search="search"
height="400"
:item-selectable="selectableProp"
item-value="name"
show-select
/>
<v-btn @click="update">update</v-btn>
</v-container>
</v-app>
</template>
<script setup>
import { computed, markRaw, readonly, ref, shallowReadonly } from 'vue'
const search = ref('')
const selectableProp = ref('selectable')
const headers = [
{ title: 'Boat Type', align: 'start', key: 'name' },
{ title: 'Speed (knots)', align: 'end', key: 'speed' },
{ title: 'Length (m)', align: 'end', key: 'length' },
{ title: 'Price ($)', align: 'end', key: 'price' },
{ title: 'Year', align: 'end', key: 'year' },
]
const boats = [
{
name: 'Speedster',
speed: 35,
length: 22,
price: 300000,
year: 2021,
selectable: true,
disabled: false,
},
{
name: 'OceanMaster',
speed: 25,
length: 35,
price: 500000,
year: 2020,
selectable: false,
disabled: true,
},
{
name: 'Voyager',
speed: 20,
length: 45,
price: 700000,
year: 2019,
selectable: false,
disabled: true,
},
{
name: 'WaveRunner',
speed: 40,
length: 19,
price: 250000,
year: 2022,
selectable: true,
disabled: false,
},
{
name: 'SeaBreeze',
speed: 28,
length: 31,
price: 450000,
year: 2018,
selectable: true,
disabled: false,
},
{
name: 'HarborGuard',
speed: 18,
length: 50,
price: 800000,
year: 2017,
selectable: true,
disabled: false,
},
{
name: 'SlickFin',
speed: 33,
length: 24,
price: 350000,
year: 2021,
selectable: true,
disabled: false,
},
{
name: 'StormBreaker',
speed: 22,
length: 38,
price: 600000,
year: 2020,
selectable: true,
disabled: false,
},
{
name: 'WindSail',
speed: 15,
length: 55,
price: 900000,
year: 2019,
selectable: true,
disabled: false,
},
{
name: 'FastTide',
speed: 37,
length: 20,
price: 280000,
year: 2022,
selectable: true,
disabled: false,
},
]
const virtualBoats = ref(
shallowReadonly([...Array(100000).keys()].map(i => {
const boat = { ...boats[i % 10] }
boat.name = `${boat.name} #${i}`
return boat
}))
)
let i = 0
function update () {
const newBoats = [...virtualBoats.value]
newBoats[i++].name = 'AAAUpdated'
virtualBoats.value = newBoats
}
function update2 () {
virtualBoats.value[i++].name = 'Updated'
}
</script>
|
This comment was marked as spam.
This comment was marked as spam.
e20cfec
to
2766105
Compare
4c970f9
to
6a3285f
Compare
Needs testing to ensure this doesn't break reactivity