eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
19.93k stars 2.49k forks source link

Opening electron.d.ts takes a long Time and causes high CPU #13772

Closed tsmaeder closed 3 months ago

tsmaeder commented 4 months ago

Bug Description:

Opening electron.d.ts blocks the IDE with high CPU

Steps to Reproduce:

  1. Open Theia source code
  2. Open electron-main-application.ts and control-click any type from electront
  3. Observe: electron.d.ts opens in a browser, then the IDE is blocked for around 15 seconds with high CPU usage.

Additional Information

tsmaeder commented 4 months ago

Note that while the IDE is blocked, no syntax coloring is visible.

tsmaeder commented 4 months ago

Note that the same operation causes no noticeable delay on VS Code.

tsmaeder commented 4 months ago

Quick profile reveals that ~100% of the time is spent in DiffComputer.computeDiff. Displaying the dirty diff seems to take a long time. Maybe https://github.com/eclipse-theia/theia/pull/13104/files introduced a performance hit we did not notice.

tsmaeder commented 3 months ago

VS Code seems to delegate diff computation to the editor service worker while we do it in the main thread. Opening electron.d.ts. one can observe a spike in CPU usage as well (although only couple of seconds, probably 10% of the time it takes Theia), but the main UI is not blocked.

tsmaeder commented 3 months ago

Since electron.d.ts is not under version control, the dirty diff is between an empty string the contents of electron.d.ts. Just doing such a line diff in a nodejs script takes over 20 seconds, so we can't expect to reduce that time significantly for that application case.

tsmaeder commented 3 months ago

I prototyped using the LcdDiff code from VS Code and that seems to be orders of magnitude faster. WTF?

tsmaeder commented 3 months ago

Turns out jsdiff itself seems to have made great strides since the 3.x version we have been using: simply updating the library makes the problem totally disappear (diff takes miliseconds).