wordplaydev / wordplay

An accessible, language-inclusive programming language and IDE for creating interactive typography on the web.
Other
61 stars 28 forks source link

Stepping through characters in editor is very delayed #508

Open azmec opened 3 months ago

azmec commented 3 months ago

Expected behavior

When editing program text, pressing either of the left or right arrow keys should move the cursor to the left or right with negligible delay. Similarly, when holding either the left or right arrow keys, releasing the left or right keys should halt the cursor with negligible delay.

Actual behavior

Instead, there is considerable delay in the cursor's movement or cessation of movement.

Provide detailed steps that consistently reproduce the behavior, including any example code. If you can, make the steps as minimal as possible, finding the smallest possible set of steps that still produce the unexpected behavior.

  1. Open the "Floating Foods" project example (code reproduced below).
    
    food: "🥮🍵🧋🥟🍛🍜🍱🍘🍢" ÷ ""

latest•['']: food … ∆ Time(1000ms) … latest.replace(Random(1 6) food.random())

Group( Grid(3 3m 1m 1m) latest.translate( ƒ(dish•"" index•#) Phrase( dish name: "\dish-\index\" entering: Pose(opacity: 0 scale: 2) resting: Sequence(sway(360°) duration: 4s) duration: 1s ) ) )


2. Move the cursor to `latest.translate`.
3. Hold down the left arrow key for 5 seconds. Release the key.
4. Observe the cursor continues to move despite the left arrow key being released.

## Profiler

I have attached a profile of Firefox when performed the steps enumerated above ([Firefox 2024-07-02 14.53 profile.json(1).gz](https://github.com/user-attachments/files/16074716/Firefox.2024-07-02.14.53.profile.json.1.gz)). To view,

1. Visit <https://profiler.firefox.com>.
2. Download the above profile and load it into the profiler.

## Environment

Desktop

- OS + version: Void Linux x86_64 6.6.35_1
- Browser + version: Firefox 127.0.2_1
azmec commented 3 months ago

I attempted to reproduce this behavior on Void Linux x86_64 6.6.35_1 with Chromium 126.0.6478.55_1, but the behavior was not observed.

The cursor would halt even when an arrow key is held down whenever the containing text flashed pink to indicate activity, but this behavior is distinct from the one described in this issue.

amyjko commented 2 months ago

Thanks @azmec. Is this still reproducible on your machine? I downloaded the latest version of Firefox and can't reproduce. I examined the profile you shared, and it looks like the primary source of slowness might have been garbage collection. That would make sense — the way Wordplay is implemented uses a lot of immutable data, and so it's constantly creating things and discarding them, leaving a lot of short lifespan data for the browser to clean up.

How much RAM does your machine have? (I'm testing on a M3 with 24 GB, so if that were the cause, that would explain why I'm not seeing it).

azmec commented 2 months ago

@amyjko, I can still reproduce the behavior on my machine.

My machine has 16GB of RAM installed and an AMD Ryzen 7040U. Firefox's about:support page indicates it has access to only 14.3 GB of RAM.