{"id":9,"date":"2019-02-05T19:54:00","date_gmt":"2019-02-05T19:54:00","guid":{"rendered":""},"modified":"2023-11-17T16:40:03","modified_gmt":"2023-11-17T16:40:03","slug":"android-performance-story","status":"publish","type":"post","link":"https:\/\/ahm.basfinans.com\/index.php\/2019\/02\/05\/android-performance-story\/","title":{"rendered":"Android Performance Story"},"content":{"rendered":"<p>I am developing a personal finance application and it&nbsp;uses SQLite&nbsp;to store all of its data. I had slowness in the application where I calculate balance for all accounts.<\/p>\n<p>The first thing that came to my mind is that the DB access is slow and I have to research if I should add indexes to the tables. Before doing that, I gave Android Studio Profiler a try.<\/p>\n<div style=\"clear: both; text-align: center;\">\n<a href=\"https:\/\/ahm.basfinans.com\/wp-content\/uploads\/2019\/02\/profile0.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" data-original-height=\"761\" data-original-width=\"1600\" height=\"190\" src=\"https:\/\/ahm.basfinans.com\/wp-content\/uploads\/2019\/02\/profile0-300x142.png\" width=\"400\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\">\n<a href=\"https:\/\/developer.android.com\/studio\/profile\/android-profiler?gclid=Cj0KCQiAheXiBRD-ARIsAODSpWPP_hSrdYAAg_s4EDtYvOh_YOCM9ulba7Zu5H02SDqqcvQwjWJBl2waApwWEALw_wcB\" target=\"_blank\" rel=\"noopener\">Android Studio Profiler<\/a><\/div>\n<p>What was a surprise to me is finding the slowness is not related to database access&nbsp;but to date conversion function. See:<\/p>\n<p><\/p>\n<div style=\"clear: both; text-align: center;\">\n<a href=\"https:\/\/ahm.basfinans.com\/wp-content\/uploads\/2019\/02\/profile1.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" data-original-height=\"160\" data-original-width=\"482\" height=\"131\" src=\"https:\/\/ahm.basfinans.com\/wp-content\/uploads\/2019\/02\/profile1-300x100.png\" width=\"400\" \/><\/a><\/div>\n<p>\nSee this code snippet,<\/p>\n<p>Class DateUtils {<\/p>\n<p>const val YYYY_MM_DD_HH_MM_SS_S = &#8220;yyyy-MM-dd HH:mm:ss&#8221;<br \/>\nprivate val formatter = SimpleDateFormat(YYYY_MM_DD_HH_MM_SS_S, Locale(&#8220;en&#8221;))<\/p>\n<p>fun toDate(dateString: String) : Date&nbsp; = formatter.parse(dateString)<br \/>\n&#8230;<\/p>\n<p>}<\/p>\n<div>\n<\/div>\n<div>\nAlthough the formatter&nbsp;object is created once and reused by the toDate() function, the toDate() is extremely slow. Although it is being called for each fetched row from SQLite, I did not expect it to be the performance bottleneck. I always assume DB access is the slowest part of any application which, in my little story, is wrong.&nbsp;<\/div>\n<div>\n<\/div>\n<div>\nSo I learned, do not assume, get data and then decide.<\/div>\n<div>\n<\/div>\n<div>\n<\/div>\n<div>From ahm507.blogspot.com<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I am developing a personal finance application and it&nbsp;uses SQLite&nbsp;to store all of its data. I had slowness in the application where I calculate balance for all accounts. The first thing that came to my mind is that the DB access is slow and I have to research if I should add indexes to the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":245,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/posts\/9"}],"collection":[{"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/comments?post=9"}],"version-history":[{"count":1,"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":247,"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/posts\/9\/revisions\/247"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/media\/245"}],"wp:attachment":[{"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/media?parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/categories?post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ahm.basfinans.com\/index.php\/wp-json\/wp\/v2\/tags?post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}