lsp4j
lsp4j copied to clipboard
custom json serializer to speed up symbol query performance
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?
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.
I experimented with a custom type adapter. It brought us a little speedup, but not a substantial one.
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?
It should be available on Sonatype Snapshots.
I also created a Gitpod snapshot for running my little performance measurement:
Enter ./gradlew :org.eclipse.lsp4j:performanceTest in the terminal to run it.
Yeah, not a huge difference, but a difference... :-) Thanks for taking a look into this and trying this, much much appreciated.