Skip to content

TypedArray updates not working in Runes Mode #14754

@hykilpikonna

Description

@hykilpikonna

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy