-1

I'm about to start a program that is constantly getting information from a web API so I want it read the API JSONs as fast as possible in order not to lose any time (I want to check some values that are constantly updating).

As I'm coding using Java, I thought I could use gson to parse those JSON information but I don't know if it's the most efficient way.

Also, is Java a good language in order to read APIs efficiently?

user157629
  • 624
  • 4
  • 17

1 Answers1

1

If it's about performance there are some issues to look at / to optimize:

  • query speed for the data (e.g. the used http or network client)
  • speed of parsing the result
  • speed of the output of the data
  • ....

If you want to improve the performance, I would suggest you analyze at first, where the most performance is lost in that chain, for example by logging durations for each part. When you found the bottleneck, you can improve it and measure it again, to see wether your program became faster.

For example you could perhaps use UDP instead of tcp. Or use http2 instead of old http protocol and so on.

If it's really the parsing part, which makes critical durations, you could try to use the fact, that the data is always in the same structure. For example you could look at "keywords" in your JSON format and extract the text right before or after these keywords. Then your program doesn't have to parse (or "understand") the whole structure and can operate (possibly) faster. Or you can extract the facts you search for with certain positions (for example the info is always after the sixth curly open brace).

But you should only optimize, if it's a real performance gain (see first part of the answer) because it's quite likely that your code gets less readable, when you optimize it for the sake of performance. That's often the tradeoff, one has to choose.