@@ -2137,33 +2137,33 @@ export const template_visitors = {
2137
2137
}
2138
2138
2139
2139
// The runtime needs to know what kind of each block this is in order to optimize for the
2140
- // immutable + key==entry case. In that case, the item doesn't need to be reactive, because
2141
- // the array as a whole is immutable, so if something changes, it either has to recreate the
2142
- // array or use nested reactivity through runes.
2143
- // TODO this feels a bit "hidden performance boost"-style, investigate if there's a way
2144
- // to make this apply in more cases
2140
+ // key === item (we avoid extra allocations). In that case, the item doesn't need to be reactive.
2141
+ // We can guarantee this by knowing that in order for the item of the each block to change, they
2142
+ // would need to mutate the key/item directly in the array. Given that in runes mode we use ===
2143
+ // equality, we can apply a fast-path (as long as the index isn't reactive).
2145
2144
let each_type = 0 ;
2146
2145
2147
2146
if (
2148
2147
node . key &&
2149
2148
( node . key . type !== 'Identifier' || ! node . index || node . key . name !== node . index )
2150
2149
) {
2151
2150
each_type |= EACH_KEYED ;
2151
+ // If there's a destructuring, then we likely need the generated $$index
2152
+ if ( node . index || node . context . type !== 'Identifier' ) {
2153
+ each_type |= EACH_INDEX_REACTIVE ;
2154
+ }
2152
2155
if (
2156
+ context . state . analysis . runes &&
2153
2157
node . key . type === 'Identifier' &&
2154
2158
node . context . type === 'Identifier' &&
2155
2159
node . context . name === node . key . name &&
2156
- context . state . options . immutable
2160
+ ( each_type & EACH_INDEX_REACTIVE ) === 0
2157
2161
) {
2158
- // Fast-path
2162
+ // Fast-path for when the key === item
2159
2163
each_item_is_reactive = false ;
2160
2164
} else {
2161
2165
each_type |= EACH_ITEM_REACTIVE ;
2162
2166
}
2163
- // If there's a destructuring, then we likely need the generated $$index
2164
- if ( node . index || node . context . type !== 'Identifier' ) {
2165
- each_type |= EACH_INDEX_REACTIVE ;
2166
- }
2167
2167
} else {
2168
2168
each_type |= EACH_ITEM_REACTIVE ;
2169
2169
}
@@ -2289,7 +2289,7 @@ export const template_visitors = {
2289
2289
)
2290
2290
: b . literal ( null ) ;
2291
2291
const key_function =
2292
- node . key && ( each_type & 1 ) /* EACH_ITEM_REACTIVE */ !== 0
2292
+ node . key && ( ( each_type & EACH_ITEM_REACTIVE ) !== 0 || context . state . options . dev )
2293
2293
? b . arrow (
2294
2294
[ node . context . type === 'Identifier' ? node . context : b . id ( '$$item' ) ] ,
2295
2295
b . block (
0 commit comments