I have the following edge case:
- I am generating large lists of data to create a world map for a game
- The generation process is batch processing a least 1000-1500 Messages but it can be way more depending on the world map size
- Since it would block the main thread if I would do it synchronously, I subscribed to
Time.every 0 TakeMessageAndProccessIt
to process each message (not animation frame , this would be too slow - 60fps only). It takes about 6 seconds to process about 1400 Messages, and I noticed that about 4 Seconds of it, it is idle ! I understand why there is idle time, but why is it so much ? Should I process multiple Messages in each step (Problem is also that some Messages in the Batch use Cmd withRandom.generate
) ?
Here a small footprint of my Performance Profile:
Can you see the idle gaps ?
So my question is: Is there a way to make this better ? I also thought of a Web Worker to process this long calculations …
These are my messages for each field in the map: (Except DroppedGenerationDataForPerformance
, SetCurrentEcoSystemType
, SetBiomeList
, EndStep
)
type GenerationStepMsg
= DroppedGenerationDataForPerformance
| SetCurrentEcoSystemType EcoSystemType
| SetBiomeList (List Biome)
| RollRandomCoordinate (List WorldSpace -> Random.Generator Int) (List WorldSpace)
| RollRandomBiome (List Biome -> Random.Generator Int)
| RollChunkTreesSubCoordinates (List.Nonempty.Nonempty Tree -> Random.Generator (List ScreenSpace))
| RollChunkTreeTypes (List.Nonempty.Nonempty Tree -> Random.Generator (List TreeType))
| AddChunkToGlobalList
| DropPickedBiomeFromBiomeList
| CreateChunk (EcoSystemType -> Biome -> WorldSpace -> Chunk)
| CalculatePossibleCoordinates (List Chunk -> List WorldSpace)
| EndStep