bluebubbles-app icon indicating copy to clipboard operation
bluebubbles-app copied to clipboard

Add index to Message model to speed up queries?

Open gsxdsm opened this issue 1 year ago • 2 comments

I ran a quick profiling of the Android app after noticing a lot of cpu/battery use when loading chats - about 50% of the CPU time was spent in Chat.getMessages. I took a look at the model (io/message.dart) and noticed there wasn't an index on the id or guid - maybe I'm missing something (not super familiar with ObjectBox), but I'm thinking an index here could improve query performance?

I'll run a few more tests locally but wanted to see if this was already investigated or I missed anything.

Thanks!

gsxdsm avatar Jan 02 '24 05:01 gsxdsm

So it looks like the index doesn't really matter - but Chat.latestMessage (chat.dart:309) appears to be a very expensive query

gsxdsm avatar Jan 02 '24 07:01 gsxdsm

I think we need to add the index on the created date column.

Since the date created date is ultimately what we query most by, we can annotate the model with @Index to make queries faster: https://docs.objectbox.io/entity-annotations

Right here: https://github.com/BlueBubblesApp/bluebubbles-app/blob/d0257c9080e82140602340b48f85fa148721553c/lib/models/io/message.dart#L241

We can also just do this to any column in the DB that we tend to use when querying. It uses more RAM, but increases read speeds

zlshames avatar Apr 12 '24 02:04 zlshames