Input on data structure & architecture to optimize for performance

Hi! My iOS/Android app is unbelievably slow and I am looking into making some optimizations on the database, so I was wondering… In the scenarios listed below, which one is the better options of the 2? Again; I am optimizing for speed for the users, not scaleability. These scenarios can be generalized, I am very aware that there’s several other factors important when making these decisions, but just looking for speed input. I would love input from people with technical knowledge, rather than anecdotal experiences.

Scenario 1: You want to label different types of images (fixed labels) and visually show a label in the front-end. Is it faster to

  • Create a text property automatically assigning 1 of 7 strings + filtering on “String = X” in the front-end.
  • Create 7 boolean fields and show label based on “Boolean=TRUE”

Scenario 2: In the front-end you want to show a list of pictures and a list of files (separately)…Is it faster to

  • Create 1 database property (document) with a text field to identify image or file and generating 2 lists of documents, filtering on the type.
  • Create 2 database properties and generating 2 different lists in the front-end

Scenario 3: You want users being able to leave reactions on images.
Is it faster to

  • Store the reactions as a new database collection and link it to the image collection. In the UI you create a list view on the current image.
  • Create more properties on the image collection. In the UI, you can immediately use the fields on the current image.
    (In general is it preferred to have parent-child relationships OR store a bunch more fields on the parent)

Thank you!

These are great questions! Here are some insights on optimizing for speed:

Scenario 1:

Option 2: Creating 7 boolean fields and showing the label based on Boolean=TRUE is generally faster. Boolean comparisons are faster than string comparisons, and they reduce the complexity of filtering.

Scenario 2:

Option 2: Creating 2 database properties and generating 2 different lists in the front-end is more efficient. This approach avoids the need for filtering and directly accesses the relevant lists, which can be faster.

Scenario 3:

Option 1: Storing reactions as a new database collection and linking it to the image collection is usually better. This allows for better normalization, easier scalability, and simpler queries. Additionally, it keeps your main collection less cluttered, improving read performance.

In general, using parent-child relationships (normalization) is preferred over storing a bunch more fields on the parent, as it improves database performance and reduces redundancy.

I hope this helps with your optimization efforts!

Best regards,
Victoria
KMFusa