-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed as not planned
Description
Describe the bug
TLDR:
Screen.Recording.2024-12-18.125121.x264.25.mp4
In legacy mode, I could update one element of a TypedArray and the corresponding update would be O(1):
<script lang="ts">
let n = 10 ** 7
let count: Int8Array = new Int8Array(n)
const increment = () => {
count[0] += 1
}
</script>
<button onclick={increment}>
count is {count[0]}
</button>
In Runes mode, I cannot do that. The following code does not work. The array is updated but the reactivity is lost, no DOM elements are updated:
<script lang="ts">
let n = 10 ** 7
let count: Int8Array = $state(new Int8Array(n))
const increment = () => {
count[0]++
}
</script>
<button onclick={increment}>
count is {count[0]}
</button>
If I however copy the array on each call, DOM elements are updated but it takes significantly more time (an O(N) operation for a O(1) change)
<script lang="ts">
let n = 10 ** 7
let count: Int8Array = $state(new Int8Array(n))
const increment = () => {
// Copy array
const tmp = Int8Array.from(count)
tmp[0]++
count = tmp
}
</script>
<button onclick={increment}>
count is {count[0]}
</button>
Reproduction
https://svelte.dev/playground/9470398dceac4efebf694c307a04b452?version=5.14.4
Logs
No response
System Info
System:
OS: Windows 11 10.0.22631
CPU: (16) x64 AMD Ryzen 7 7840HS with Radeon 780M Graphics
Memory: 3.75 GB / 27.69 GB
Binaries:
Node: 22.5.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD
npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
bun: 1.1.38 - ~\.bun\bin\bun.EXE
Browsers:
Edge: Chromium (127.0.2651.74)
Internet Explorer: 11.0.22621.3527
Severity
blocking an upgrade
Metadata
Metadata
Assignees
Labels
No labels