Skip to content
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

TypedArray updates not working in Runes Mode #14754

Closed
hykilpikonna opened this issue Dec 18, 2024 · 1 comment
Closed

TypedArray updates not working in Runes Mode #14754

hykilpikonna opened this issue Dec 18, 2024 · 1 comment

Comments

@hykilpikonna
Copy link

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

@Conduitry
Copy link
Member

See #14639 and other linked issues for a draft/proposal of a feature to support this. As it stands, this would fall under the same category as other non-POJOs not having automatic reactivity.

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants