arshbot
arshbot

Reputation: 15815

Too many schemas in Realm a bad thing?

We have a use case that requires many similar but different schemas for our database. Most of these models will only have between 0 - 4 rows on average and most excluding a handful won't be used at all.

Each product we add in will require roughly 2-4 schemas (depending on the tree level as some require a list within a list)and we plan to add many products. After completion we could see over 100 schemas each with a minimal number of rows.

So the question comes up:

The alternative is to create a 'one size fits all' schema with the shared attributes and have a misc property that is used to store serialized json data. This seems hacky and I could see issues from down the line coming up from this. The pros being we'd only have a handful of schemas.

Upvotes: 2

Views: 112

Answers (2)

Thomas Goyne
Thomas Goyne

Reputation: 8138

The time to create new Realm files and open existing ones will scale somewhat with the number of object types in your schema, so in theory that could eventually matter. In practice the fixed costs of creating or opening a file dwarf that until you have hundreds of object types, and even then it may not be slow enough to be a concern at all.

Once the Realm file is open there should be no performance implications to a very large number of object types.

Upvotes: 0

Gui Herzog
Gui Herzog

Reputation: 5615

I do not have an objective answer for that, however, I will share a bit of my experience implementing Realm.

My application has around 50 schemas and I have not seen yet any problem with that.

I have also tried your alternative solution before (one size fits all) and I am can almost assure that this solution is much worse than having too many schemas. The time you will lose de/serializing json data is gonna make your app really slow.

I hope it helps or at least give you a feeling of the way to go.

Upvotes: 4

Related Questions