We are using Bahmni Connect(Android) for a client and have noticed the following areas where the app could be optimised:
- It takes quite a lot of time to open the Consultation forms.
Once you open the Consultation for a particular patient it takes quite a while to load the page. Almost a minute for us using a tablet with the configuration mentioned below
Ram: 2 GB.
CPU: 1.3 Ghz Quad Core
Total events: ~5100
After some investigation and debugging we found out that the problem lies here :https://github.com/Bahmni/bahmni-offline/blob/320aa65a0e2886146c28232f714d9c5761cabacb/android/platforms/android/src/main/java/org/bahmni/offline/dbServices/dao/FormDbService.java#L57
The sql uses the
SELECT * from form syntax and on lines 65 to 67 we are only using 3 columns from the table i.e. ‘name’, ‘version’, ‘uuid’.We have some forms that have around 500 concepts. Due to this the query is retrieving all the forms data which is not necessary. After changing the query to just retrieve the necessary fields we saw a huge performance boost. The time taken to open the consultation page dropped from a minute to less than 10 seconds which is a 6x performance boost.
Similarly it also takes a lot of time to save the Obs form data after filling in some data. But this was due to the fact that getAllForms() was being called again after saving and it gave the illusion that saving also takes a lot of time.
The above change also sped up the time taken the save the forms which is around 10-15 secs.
- The db connection is not closed
While checking the logs, we noticed that almost everywhere where a db connection is opened, it is never closed. For eg: https://github.com/Bahmni/bahmni-offline/blob/320aa65a0e2886146c28232f714d9c5761cabacb/android/platforms/android/src/main/java/org/bahmni/offline/dbServices/dao/FormDbService.java#L55
The db object is initialized but it is never closed which is a bad practice and may affect performance. The db connection needs to be closed after it finishes its operation.
- Unnecessary data is being sent as part of the Observation Model while saving the Obs Forms
The Android sqlite db only supports a cursor of size ~1 MB. We have a form where we have a dropdown with around 480 concepts as answers. After choosing any one of them and saving the form , we noticed that the Observation model was sending an object called
possibleAnswers containing all the 480 concepts along with it which is unnecessary. If we add the same obs again (Using the Add section config) and select a answer for the new section , it adds the
possibleAnswers to again. So thats 480 + 480, so if you keep on repeating the section which is our requirement it keeps on adding unncessary data.
Repeating the section twice itself crosses the 1 MB limit and the obs form does not save and throws a
JAVA exception. After some investigation we found out that the possbileAnswers are being added over here : https://github.com/Bahmni/bahmni-connect/blob/2131d452213a0b68c0fe9f1b26310f5e1b6c815d/ui/app/common/concept-set/mappers/observationMapper.js#L156
Removing that line solved the problem and the form data now does not exceed 20 kB.
We wanted to know the community’s thoughts on all of these issues and whether there are any better ways on tackling these issues so that these can be fixed and merged on the main Bahmni Connect Repo