Denis Brandi
1 min readMar 18, 2021

--

If you are downloading a large amount of data having too many models might be bad for performances.

What you should do in that case, assuming that is the real issue, is to keep the domain model and get read of DTOs.

DTOs are usually generated with libraries like Gson which rely on reflection (very slow and bad for performances) so I suggest you to use dynamic data structures for DTOs (JsonObject, JsonArray...) and map JsonObject to Domain model and vice-versa.

For storing in the DB, instead, you may want to use raw queries and skip ORMs since they too use reflection, also you may want to map the Json structure directly to the raw query and then map the DB cursor to the domain model after storing.

You also may want to have a look at my previous answer on a similar topic -> https://dnsbrnd.medium.com/hi-farid-thanks-for-reading-the-article-7c42c759e9a9 .

My golden rule is that you should always have a domain model, DTOs are nice to have but if there is an issue with performances these are the ones you want to remove (not the domain model!).

Manual mapping is faster than reflection, so if you have to remove something, remove the slowest, not the fastest.

--

--