diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-01-10 21:40:02 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-01-10 21:46:13 +0100 |
commit | 6c547a24cea3422d934547bc9baf28a5f9ecf139 (patch) | |
tree | 0c7b43c23fb051632937602955898c2210bc08de /src/renderer | |
parent | 4b30bda722668bef4ba362b3e578f02dede0099b (diff) | |
download | hittekaart-6c547a24cea3422d934547bc9baf28a5f9ecf139.tar.gz hittekaart-6c547a24cea3422d934547bc9baf28a5f9ecf139.tar.bz2 hittekaart-6c547a24cea3422d934547bc9baf28a5f9ecf139.zip |
considerably speed up the rendering process
Most of the time was spent doing hashmap lookups because all of our
operations were done pixel by pixel, and layer.get_pixel_mut always went
through the hashmap lookup. This was true for render_circle, render_line
*and* merge_heat_counter - the last of which iterated over the full
layer every time.
The biggest change now is that we try to do accesses tile-by-tile. For
the drawing functions, this means that we render the image on a small
patch locally, and then blit the image onto the base - tile by tile,
instead of pixel by pixel.
For merge_heat_counters, we do the same: We iterate over tiles first,
keeping a reference, and then iterate over the tile's pixels - that way
we get a *huge* speedup. I can now render level 19 in 9 seconds,
compared to before when it took 20s for level 17.
Another benefit now is that we save the heatmap as u8 instead of u32.
For a single track, we could even use a single bit (though that brings
other problems with it). For the complete heatmap, u8 is probably too
small (having 256 tracks is realistic), but we can change the merged one
to be u16 later. This allows us to cut down on the RAM the program needs
considerably, as we basically only use a fourth of the space now.
A bit of noise is introduced in this patch since I ran cargo fmt.
Side note: The bottleneck now seems to be the PNG compression, so that
would be the next area to improve upon. Either by toning down the
compression ratio (at the cost of higher storage needs), or by
leveraging multithreading to deal with that.
Diffstat (limited to 'src/renderer')
0 files changed, 0 insertions, 0 deletions