Gavin Dev Diary - TheEvergreenStateCollege/upper-division-cs-23-24 GitHub Wiki

6/3/24 Gavin-SC-HW-09

I used firefox dev tools performance tool to check the performance of my game of life. The performance was very poor. I assumed that the main cost on performance was drawing hexagons, but it was actually the wasm function get_cells(), which copies the cells array. I realized that I was calling this function for every hexagon instead of once each frame, and fixing this resulted in a much faster website, with most of the time spent drawing hexagons as expected. Around 80%.

I looked in the book for ways to optimize further and saw that the canvas context set fill style function is expensive. I was calling that function every hexagon, so I changed the code to draw each hexagon of one color, then the next, and so on. This reduced the time used by setting the fill style, but it increased the time needed to loop over the cells, so the performance remained about the same over all.

Here was the final performance result

image

I didn't optimize the rust code because it was only 5% of the performance cost