zetadin / LogistiX

A browser game about supplying an active front.
Other
0 stars 0 forks source link

map storage to database is slow #4

Closed zetadin closed 1 month ago

zetadin commented 1 month ago

A lot of tile rows have to be added to the DB on map creation. It would be faster if the map was organized in chunks (eg 32x32 tiles like in minecraft). Whole chunk would be stored as a data column containing a json with the tile information and columns for the parent map and chunk position within it. Units should be stored in a similar json structure also on a per chunk basis.

REST API would return whole chunks at once. Eg make a request for a list of chunks deemed the relevant theater.

zetadin commented 1 month ago

About 80% of the time spent in the map generation function is writing hexes to the database. For a size 40 map. Total generation time is 66ms, 55 of which is database writing.

zetadin commented 1 month ago

By storing hex data as parts of a larger JSON string spanning 32x32 hexes, database write time went down by ~ 10 times to 4.7 ms. Total map generation time is now 13.8 ms (almost 5 times speedup).

Still need to modify the REST API to provide data from these chunks.