Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The request_definition function takes much time to return result #13

Open
masterSunflowers opened this issue Dec 12, 2024 · 3 comments
Open

Comments

@masterSunflowers
Copy link

I’m using this library to retrieve definitions of code elements for Java. The request_definition function is one I use frequently. However, I’ve noticed that the first request takes about 10 to 30 seconds to complete, and in some cases, it can take as long as 100 seconds. Subsequent requests are faster, taking around 5 to 10 seconds, but this still feels excessive. I’m not sure if this behavior is normal, but it’s too slow for my needs.

@LakshyAAAgrawal
Copy link
Collaborator

Hi @masterSunflowers ,

Thanks a lot for reporting this issue. One of the goals for multilspy that I had starting out was for it to be as good a client library as VSCode is (since most language servers are optimized with IDEs in mind).

The reason you see a larger response latency in the first request, and lesser in subsequent ones is because Eclipse JDTLS builds the repository before setting completions available. Could you please try and launch the same repository you launched with multilspy in VSCode, and try to benchmark the latencies you see there, both for the first request and subsequent requests?

I would be happy to work on fixing any latencies introduced specifically by multilspy.

@masterSunflowers
Copy link
Author

Hi @LakshyAAAgrawal,

Thank you for taking the time to help me out. I’ve realized that the latency issue is primarily caused by my implementation. Specifically, for each request_definition, I call:

with lsp.start_server():
    result = lsp.request_definition(params)

This means that for every request, there is additional latency due to creating a context with lsp.start_server.

However, when I tested this across various projects, I encountered another problem: in some cases, the with lsp.start_server() command takes an unusually long time, seemingly hanging indefinitely.

After reviewing the logs, I noticed the following:

INFO:multilspy:{"time": "2024-12-13 06:27:20", "level": "INFO", "caller_file": "eclipse_jdtls.py", "caller_name": "window_log_message", "caller_line": 353, "message": "LSP: window/logMessage: {\"type\": 3, \"message\": \"Dec 13, 2024, 6:27:20 AM Finished creating the Java project jdt.ls-java-project\"}"}
INFO:multilspy:{"time": "2024-12-13 06:27:20", "level": "INFO", "caller_file": "eclipse_jdtls.py", "caller_name": "window_log_message", "caller_line": 353, "message": "LSP: window/logMessage: {\"type\": 3, \"message\": \"Dec 13, 2024, 6:27:20 AM Importing Maven project(s)\"}"}

Does the language server in your implementation actually install or import all Maven projects during startup? If so, that would explain why it takes so much time to initialize.

@LakshyAAAgrawal
Copy link
Collaborator

This means that for every request, there is additional latency due to creating a context with lsp.start_server

I certainly expect this will take a lot of extra time. Can you try to do the lsp.start_server just once per repository you want to use?

Does the language server in your implementation actually install or import all Maven projects during startup? If so, that would explain why it takes so much time to initialize.

Please have a look at

"trace": {
"server": "verbose"
},
"import": {
"maven": {
"enabled": true,
. Specifically, the logs are set to verbose, which could be (slightly) slowing things down. Further, it does import all Maven projects within the directory in which multilspy is launched.

Can you suggest a better way to handle multi-project Java repos?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants