UI Freezes and the Dangers of Non-Cancellable Read Actions in Background Threads | The JetBrains Platform Blog
Blog post from JetBrains
In JetBrains IDEs, UI freezes are often attributed to heavy work on the Event Dispatch Thread (EDT), but a significant cause can also be traced to long, non-cancellable read actions running in background threads, particularly within plugins. These actions, which are not inherently cancellable, can block write actions and freeze the UI, as they demand exclusive access when write actions are requested. The IntelliJ Platform employs a reader-writer lock system, allowing multiple read actions to run concurrently but requiring read actions to complete before a write action can proceed. When these read actions are lengthy, they prevent necessary write actions from occurring, thus freezing the UI. To mitigate this issue, it is advised to avoid using ReadAction.compute for long tasks in background threads, and instead, utilize cancellable read actions or split tasks into smaller, manageable chunks. The article highlights the importance of rewriting plugin code paths to prevent UI freezes, emphasizing that non-cancellable reads can significantly affect platform performance. Upcoming sessions aim to guide developers on creating freeze-safe plugin code to maintain the responsiveness of JetBrains IDEs.