Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Packages are allowed to hang Sublime Text Indefinitely #1463
Packages are allowed to hang Sublime Text Indefinitely
For example, a plugin command call may enter on
This behavior can be noticed on several applications as the Mozilla Firefox. But on other applications as Google's Chrome it is not true. The nature around Google's chrome is that everything dangerous is spammed on separate thread, and soon as the Chrome's Task Manager noticed hand/blocking threads, it prompts to the user's whether to kill them or wait.
The simple thing for this is not run unknown procedures on the main Sublime Text process, as any simple thing may hang. Only run certain deterministic procedures on the main Sublime Text process and a create watchdogs for trouble some routines.
Another example is the SQLExec package, if the start a connection to the SGBD and the SGBD prompt for the password. The package was not expecting it, then Sublime Text hands indefinitely doing absolutely nothing as it is waiting for the user to put the password, event which will never happen.
Is expected that packages are not allowed to hang Sublime Text indefinitely.
If some package enters on while true or takes too much to perform its actions, Sublime Text may hang indefinitely.
Steps to reproduce
Firefox has recently been updated so that tabs are rendered on a separate thread and I hate it. Why? Because, before, I used to be able to instantly switch tabs, and now, with electrolysis, I get a loading icon for a second first. :(
So I feel there is a danger that adding functionality to check if a plugin has "stalled" will degrade performance too much. Note that plugins can be profiled using
Eclipse IDE asks the user whether they want to disable all extra features as syntax highlight, word-wrap and etc, before opening a big file. So the user may choose whether to wait more and get all features, or open early with no extra features. Sublime could do the same.
Yeah, Sublime text has a loading bar, I tested opening 1GB file, and it allowed to cancel closing the file hitting by
For 1GB file, it required a little more than 1GB of RAM's Memory. But right after filling the progress bar, Sublime Text hanged for 20 some seconds. Then after it became responsive, I tried to interact with the file and Sublime Text hanged using all its CPU.
For now, 5 minutes has passed and it still hanging, so I am killing the process. This 5 minutes hang after opened the file is because of issue #1463 Packages are allowed to hang Sublime Text Indefinitely.
Because when I did the same on a Vanilla Install, Sublime Text only hanged for 20 seconds right after the loading bar got filled. After it It was completely responsive! Good work. Now we know Sublime Text may handle 1GB files, but only the Vanilla version, because if there are more packages installed, they will hang Sublime Text due the issue #1463 Packages are allowed to hang Sublime Text Indefinitely.
This would require some major architecture considerations.
Either way, there are actions that you want to happen synchronously, as @keith-hall indicated, because the user shouldn't see UI changes before a plugin has done work. A good example for this would be the InactivePanes package, where you would see flickering if it was executed asynchronously.
On the other hand, plugins should realize by themselves whether they are running time-critical tasks and should otherwise resort to the
In fact it is a main design principal of Google to do so. In Android nothing else but the GUI is allowed to be handled by the main thread. All expensive (I/O) operations must be handled by extra threads. This is the only way to keep GUI responsive under all circumstances and makes rich animations possible. Especially all I/O operations must not be done in the main thread as each of them may block a thread for seconds, if the IO device needs time to wakeup or so.
And the principle "everything is asynchronous" is the main reason for Node to be so powerful. It uses libuv / libev to access all I/O devices asynchronously with a kind of common OS independent messaging system. This results in very low CPU waits in the thread handling the
The drawback as @FichteFoll outlines is a high effort to keep track of all that asynchronous tasks and to sync their results into the main thread for GUI updates.
@FichteFoll: To avoid unwanted GUI updates I could think of API functions like
The following example should outline a way to handle expensive async jobs, no matter whether the Thread was created by SublimeText or the plugin itself.
def PluginWorker(): ... # do the time expensive job in the background ... # sync with main thread try: sublime.begin_update() # freeze repaint view.settings().set("font_size", new_size) view.settings().set("font_name", new_name) ... finally: sublime.end_update() # enable and do repaint
I know about the really hard job to handle async operations, but I agree with @evandrocoan Sublime Text should not loose control to one or more unresponsive plugins. It may not be useful to run each plugin in its own thread but at least to run them all in one seperate one, to keep GUI responsive and enable SublimeText to kill an unresponsive task.
The next release of GitGutter will be a good example to learn, how to correctly run time-critical tasks asynchronously, from plugin side. All of the steps required to build the gutter icons (call git -> call diff -> ...) are chained by a
The main entry point to run each type of task async is by starting it with
The plugin interferes with main thread only very little which results in no more lags when typing.
The conclusion is: Maybe this type of async task handling could become part of the sublime_api as base for other plugin developers, too. This would avoid deep changes in the core code and could provide everything to run time critical tasks safely without loosing control.
I also had a look on python's default library and found
This leaves only one question: How to ensure plugin developers make use of those features to ensure quality of service?