Thank you for your answer!
Agree, some parts of my code are not above suspicion… cf below
This morning I finally isolated the small code portion that was problematic (in the tilemaps script), and really… this is just ONE (old) function but with tons of loops …
I created this function months ago and used it to convert the raw tilemap data into an “easy-to-use” 2-dimension tables (per layer). Super useful, but probably not elegant/optimized.
(I have a question about all these loops at the end but maybe you’ll already see obvious bad practices at this point?)
Anyway, this morning I’ve been proceeding with easy adjustments and changed the loading times from 7.5s to 1.8s (html5)
1/ I replaced the remaining tablelength() functions (from the time I was a complete beginner with Defold / Lua… ) with the # operator (#lua_tileset_table replaced tablelength(lua_tileset_table)
=> huge gain (like -50% loading times… wow)
2/ I removed some layers from my tilemap (keeping the essential ones only)… to reduce the number of loops.
From
To
This second adjustement is like a sacrifice, I must say but for now, more layers also mean longer loading times, so…
At this point, even though I’d prefer to have instant collection loading times the result is acceptable.
The 4 loops seem to be the core problem, so maybe I’ll have to rethink the way I read and “reformat” the tilemap data… I don’t know.
But I’m wondering… Is there a way to optimize the loops themselves? (in terms of pure code)
I have 4 “for” inside each other but I don’t know if there is a more elegant/optimized way than just a brutal “for for for for”…