lsp-wl icon indicating copy to clipboard operation
lsp-wl copied to clipboard

Cut down initialization time for debugger (and server)

Open hongyi-zhao opened this issue 3 years ago • 6 comments

On Ubuntu 20.04, I use the latest stable vscode and the git master version of lsp-wl. I noticed the following strange problem: after login into the system, the first time running of the "Start Debugging F5" with the lsp-wl will fail with the following error:

image

The easy and quick way to fix this problem is running the math or mathematica commands once. Other workarounds, based on my observation, including, but may not be limited to, the following way: Click on the "Cancel", and then re-run the "Start Debugging F5" for several times, the problem will finally disappear.

Afterwards, if I close the vscode, then restart it, the problem doesn't appear again. More specifically, the problem occurs only when F5 is called from vscode for the first time after logging into the system.

Regards, HY

hongyi-zhao avatar May 27 '21 12:05 hongyi-zhao

Can you make sure that the language server itself is fully started before you press F5? It works w/o any problem on my side.

kenkangxgwe avatar May 29 '21 11:05 kenkangxgwe

But indeed, if you press F5 immediately after the project is opened, it will give you ECONNREFUSED

kenkangxgwe avatar May 29 '21 11:05 kenkangxgwe

It seems that the only Mathematica process is shown below when the ECONNREFUSED occurred:

werner@X10DAi:~$ ps -aux| grep Mathematica |grep -v grep
werner   1219502 56.0  0.0 4333932 224784 ?      Rl   21:18   0:33 /opt/Wolfram/Mathematica/12.1/SystemFiles/Kernel/Binaries/Linux-x86-64/WolframKernel -script ~/Public/repo/github.com/kenkangxgwe/lsp-wl.git/init.wls --socket=6536 --clientProcessId=1218208

And, after the debug process started successfully, the Mathematica processes will look like following:

werner@X10DAi:~$ ps -aux| grep Mathematica |grep -v grep
werner   1219502 48.3  0.0 4713876 251100 ?      Rl   21:18   0:39 /opt/Wolfram/Mathematica/12.1/SystemFiles/Kernel/Binaries/Linux-x86-64/WolframKernel -script ~/Public/repo/github.com/kenkangxgwe/lsp-wl.git/init.wls --socket=6536 --clientProcessId=1218208
werner   1268623 10.4  0.0 1039668 150784 ?      SNl  21:19   0:01 /opt/Wolfram/Mathematica/12.1/SystemFiles/Kernel/Binaries/Linux-x86-64/WolframKernel -subkernel -noinit -nopaclet -wstp -linkprotocol SharedMemory -linkconnect -linkname 2pk56_shm

So, it seems that the problem is caused by the slow initialization of the language server itself when invoked from vscode.

hongyi-zhao avatar May 29 '21 13:05 hongyi-zhao

This might be (and should be) tolerated, because it takes some round trips for the server to communicate with the editor to start the debugger. Will look into refactorings to accelerate the initialization but not in high priority.

kenkangxgwe avatar May 30 '21 08:05 kenkangxgwe

Please note the following conclusion which I've drawn previously:

The easy and quick way to fix this problem is running the math or mathematica commands once.

This method, especially starting the terminal version with the math command, only needs very short time to solve this problem.

hongyi-zhao avatar May 30 '21 08:05 hongyi-zhao

I don't see why it is a fix, since invoking another process will take even longer time. According to my measures, the current initialization time for the server is ~3.47s. Opening the debug port adds ~0.02s while running the math will add ~1.06s.

kenkangxgwe avatar May 30 '21 09:05 kenkangxgwe