typedb / typedb-studio

TypeDB Studio (IDE)
https://typedb.com
Mozilla Public License 2.0
191 stars 44 forks source link

Studio freezes when undoing/redoing changes to large chunks of text #599

Closed tomassabat closed 1 year ago

tomassabat commented 2 years ago

Description

Studio freezes and has to be restarted when undoing/redoing changes that affect large chunks of text.

Environment

  1. TypeDB version: 2.11.1
  2. OS of TypeDB server: MacOS 12.1
  3. Studio version: 2.11.0
  4. OS of Studio: MacOS 12.1

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Select any large chunk of text in Studio (e.g. 200+ lines)
  2. Use the tab button many times to create indentations
  3. Studio should freeze
jamesreprise commented 1 year ago

Rapidly hitting tab is sufficient to overload Studio: the undo/redo actions isn't necessary to cause freezing. Edited the original issue post to reflect this.

jamesreprise commented 1 year ago

It appears as though the rate at which the indents and outdents are performed is the biggest factor.

Performing 10 indent one second apart is completely fine. The increase in memory usage is nominal (20MB or so). Doing it quickly freezes the program, allocating enormous amounts of memory (up to 6GB) in the process.

I suspect that there is some sort of backpressure issue here, where if actions aren't processed quickly enough Compose locks up.

Edit: Found a cause: TextProcessor:435 delay(Duration.milliseconds(TYPING_WINDOW_MILLIS)). We launch a coroutine that delays and then tries to repeatedly decrementandget changeCount, an atomic integer. Some sort of locking problem. I don't think it's sufficient to remove the delay, however there is a huge increase in responsiveness once we do so.

jamesreprise commented 1 year ago

This is no longer reproducible on the development branch after other work has been done upgrading compose and making changes to how the text editor functions under the hood. Closing.