Looking for advices on how to structure my project and optimize performances

edit : my 1st message was probably messy and unclear (so nobody answered it :grin:) because my mind was not clear itself at this moment.

Just added a 2nd message to summarize my point/question.

My 1st message may be pretty messy, so… I’ll simplify and reformulate it:

Let’s say you want to build a “build&fight” game (ex: clash of clans), where users will frequently switch from one scene to another (build <> fight).

Would you have
1/ 1 collection per “scene” (1 collection for the building phase, 1 collection for the battle phase… each of them containing 1 tilemap)
2/ 1 collection for both (including 2 tilemaps… so the loading times between each scene are faster?)

Are there reasons not to use the 2nd option? :thinking:

I would use multiple collections and unload the other when not used, it would give better performance.

1 Like

My thinking is that it’s a trade-off between processing power (loading new collection) and memory (storing multiple assets in RAM).

If you are concerned about loading times, I would try to have everything in one collection.

Can you make a test of either version to get a feel for it? Make sure to use the profiler tools as well.


Having 1 collection per playable “scene” is nice, because then one can set it as the bootstrap collection in the game, and it is easy to start and debug that particular “scene”.

It all depends on how you like to split things up, and how much iteration you expect to do in a scene. E.g. are you developing them one after another, or both at the same time?

so the loading times between each scene are faster?

I’ve touched on this subject before.
The loading is probably going to be very fast anyways, but if this is your concern
all we can give you are good guesses. Only you will know what will actually be inside your collections.
I advice you to create a test where you switch between the two scenes, and the scenes are “fully” implemented in terms of tilemap size, number of sprites etc.
Once you have that, you measure the time it takes to load and decide if that’s ok or not.


This is a really big advantage to this approach. It is really nice to be able to test something in isolation. But it also requires that your game is designed to handle this or that it can easily be set up like that.


Thank you for all your answers! Tons of good insights

I understand why I should have 1 collection per “gameplay scene”, this is how I organized my project until now since it’s definitely more convenient to start with a clean sheet when starting a new scene.

But still, my loading time are super long so I have to do something about that… and I know that no one can help me without knowing the project itself and how/why I made things. :nerd_face::disappointed_relieved:

Is there a way to precisely know what makes the loading time so long?

edit: (maybe I should start using the profiler :see_no_evil:)

1 Like

How long?

Not really, but what you can do is to check the profiler and build report to see what the loaded collection contains. Perhaps it has some huuuge files you didn’t know about?

1 Like

Note that I’m talking about transitions between collections, not the initial loading with “Defold” displayed (just in case)

To make it easier for you (or anyone else) to provide feedback/advice, I made 3 videos:

In my case, a collection of a specific game mode (idlebuilder / battle) contains the tilemaps of each theme (dungeon & village), I just hide dynamically the one I don’t want to be displayed. And the user can switch from a theme to another via the debug menu.

HTML5 - DESKTOP > Theme “Dungeon”

HTML5 - DESKTOP > Theme “Village”

As you can see, for some reason the “loading” (black screen when a collection is being loaded) is much longer with the “village” theme… while both are supposed to be (almost) the same.

The only differences I see between “dungeon” and “village” themes:
1/ Tilemap size: 20x70 (dungeon) vs 20x100 (village) => 32x32 tiles for both
2/ Tilemap source image size: 640x768 (dungeon) vs 640x1024 (village)
3/ Character sprite size: 96x96 (dungeon) vs 192x128 (village)
(but the chars are spawned once the collection is loaded… so no impact on the duration of the “black screen” display right?)

Except that, this is the exact same game (they even share the same game save)

What could make such a difference in terms of loading time between the 2 themes?
The tilemap size? The tilemap source image? Both?

Then I decided to isolate and keep only what was necessary for the “dungeon theme”, and removed ALL unnecessary assets (including the “village” tilemap, but also audios, most atlases etc.)

HTML5 - MOBILE > Theme “Dungeon” (“super pure version”)

The initial loading (where “Defold” is displayed) seems shorter, but the rest is pretty similar.

Why is the "battle " mode faster to load the the “idle builder” mode?

The main/only difference between both scenes is just the tilemap sizes, again…
20x70 (idle_builder) vs 20x30 (battle)

The other differences are what happens in the scene (tilemap construction, character spawning etc.) but it has nothing to do with the collection loading right?


So, in the end… What makes a collection more or less fast to load? :thinking: :anguished:

Would you have optimization tips? (ex: tilemaps)

Also note that I use a scene_controller scene/script that is used to load/update the tilemap data (everytime I load a scene)

But since it’s common to both dungeon and village themes, it probably does not explain why the idle_builder collection of the 2nd theme is much longer to load that the 1st one…

Short and simple answer: The size of the assets used by the collection.

In the case where you isolate your game to a single collection with the assets, what is the size of the individual assets? Check the build report or the files in /build folder.

1 Like

If you suspect the texture sizes, you should really also test the texture compression which should reduce the size of them.

You probably don’t want to have it on at all times, but just as a comparison to show what the user experience would be.

1 Like

I reorganized my project so it’s easier to isolate a “pure version”.

Just rebuilt in the “purest” conditions (no background nor audio, removed anything related to the 2nd theme etc.), and here is the report (maybe you’ll be able to tell me if something looks wrong)

On mobile, the idle_builder collection still takes like ~3-4s to be loaded (black screen), why is that?
The only difference between both collections is the tilemap (but the tilemap source image is the same)

You can give it a try here:

By texture compression, you mean that? (it was already enabled)


Note that is my case, the only “asset” present in the collection is the tilemap.

Everything else (upgrade buttons, characters etc.) is generated once the collection is loaded. There is almost nothing in the collection itself, so it should load instantly shouldn’t it? (and then update the tilemap, spawn the characters… I would accept that it can be laggy, but I should be able to see it being laggy - the black screen should not be there)

Could it come from what is performed before loading the collection with monarch? (in the scene_controller script, where I dynamically load the tilemap data and put them into tables etc.)

Probably not but… well, I don’t know :o . . . :neutral_face:

Good question. According to the build report there’s not much in the collection that could explain it. It looks like a 2k texture plus some other much smaller files.

What if you start with this collection as a bootstrap collection?

Are you doing heavy stuff in the init() function any script in the collection?

1 Like

For now, everything explodes :grin: since it’s not designed to be bootstrapped (some required stuff is initialized in the scene_controller script… easier this way since I couldn’t control the initialization order in the gameplay colllections)

But maybe I can tweak it to run some tests.

Yeah, I create/fill many grids, tables etc. in a few scripts (some of them being shared with the battle collection, but not all of them)

Would you recommend moving this stuff from the init() to the update() (1st frame) ?

Enabling it is one thing, configuring it is the main part.
Are you sure your atlas is compressed?
You’ll see which configuration is used in the top left corner when you have the atlas open.



I quickly configured the texture compression and used a common “default” setting (the possibility to have a unique configuration for each type of asset is cool though).

It seems to work as intended for all elements (assets contained in atlases appear more or less blurry, depending on their atlas size etc.) except… the tilemap source image.

I even entered the path of the image itself (3rd line in path settings) but… still nothing :thinking:

Did I miss something? is there something specific to know about tilemap source image compression?

Have you set the texture profile in game.project?

A quick test for me show that it’s possible to enable texture profiles for a tile source:

And then you verify it like so:

1 Like

Oh ok, I didn’t compress the tilesource but the tilesource image (png)… but it’s ok now it works :slight_smile:


Everything is ugly, as expected :slight_smile: (which is great)