lsp4j icon indicating copy to clipboard operation
lsp4j copied to clipboard

custom json serializer to speed up symbol query performance

Open martinlippert opened this issue 6 years ago • 5 comments

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?

martinlippert avatar Jan 31 '19 09:01 martinlippert

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 avatar Feb 05 '19 13:02 spoenemann

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

spoenemann avatar Feb 27 '19 12:02 spoenemann

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?

martinlippert avatar Feb 28 '19 10:02 martinlippert

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.

spoenemann avatar Feb 28 '19 10:02 spoenemann

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

martinlippert avatar May 06 '19 08:05 martinlippert