eclipse-lsp4j / lsp4j

A Java implementation of the language server protocol intended to be consumed by tools and language servers implemented in Java.
https://eclipse.org/lsp4j
Other
608 stars 144 forks source link

custom json serializer to speed up symbol query performance #299

Open martinlippert opened 5 years ago

martinlippert commented 5 years ago

While working on our language server I observed that serializing a larger number of symbols to JSON (when sending back the results for the workspace/symbol request) consumes quite a bit of time. I wonder if it would be possible to optimize this serialization specifically for symbols, e.g. by replacing the standard reflective collection serialization with a custom-made serialization for the collection of symbols.

Any idea how this could be implemented?

spoenemann commented 5 years ago

Gson allows to annotate a class or a field with @JsonAdapter to provide a type adapter factory for instances of that type or field. We already use this at several parts of the protocol to ensure we can parse and serialize correctly according to the spec. I guess this mechanism should work for performance improvement, too.

spoenemann commented 5 years ago

I experimented with a custom type adapter. It brought us a little speedup, but not a substantial one.

martinlippert commented 5 years ago

Cool to see that you found the time to experiment with that, much appreciated. Is there a way for me to try this out? Is that already available in a CI build?

spoenemann commented 5 years ago

It should be available on Sonatype Snapshots.

I also created a Gitpod snapshot for running my little performance measurement:

Open in Gitpod

Enter ./gradlew :org.eclipse.lsp4j:performanceTest in the terminal to run it.

martinlippert commented 5 years ago

Yeah, not a huge difference, but a difference... :-) Thanks for taking a look into this and trying this, much much appreciated.