This is actually based on incorrect advice, or rather, it was true at one point (I think around Java 5) that concatenation using “+” was less efficient than using a StringBuilder
, but since that point the Java compiler has been changed so that writing something like:
"This is a test string with a value of " + value + " isn't that great?"
Compiles into the equivalent call using StringBuilders
.
Optimization, though, is a hard problem that’s often to the specific operation in question and reducing the time for a query through a web API like this is… unlikely to be a simple task. Conceptually (at least) the web request looks something like this (AC = Android Client, WS = REST Webservices Module, DB = database):
AC sends request to WS
WS converts parameters into DB query and queries DB
WS takes results from DB and marshals them into JSON format
WS sends the JSON formatted response to AC
Since the query is paged, we then have the results:
AC requests next page from WS
etc., etc.
Given all these different components the question is where is the slow down? Something like VisualVM might give you and answer to that, but as you’ve noticed, it will do so at the cost of severely slowing down OpenMRS (even if it does work, you’re likely to get a lot of noise as OpenMRS does quite a lot of things).
So one way towards a quick win is to actually look at the PR the original author created. The problem with that PR seemed to be that it only works on OpenMRS 1.11 or newer. So one way to revive that would be to take that code and see if it can be reworked so that it applies to OpenMRS versions 1.11 or newer (or at least to identify the version at which it could be applied).
Another thing to look at is precisely what information does the Android Client need about concepts? Can we somehow limit down the set of data that it needs supplied from “everything” to something slightly smaller? Would it make sense (for instance) to allow the Locale of the concepts to be specified as part of the query (if it isn’t already) and only return concept names that matched a specified locale? Does the Android Client request specify that it only needs concepts that are not retired?