Re:“Clean” Code, Horrible Performance
by LorenPechtel on Wednesday March 01, 2023 @05:08PM
(#34989029)
Hot loops are where you spend your optimizing efforts. If you're going through that list of shapes again and again it very well might be worthwhile to cache some data and provide the objects with a way to update the cache.
[ Parent
| on HN ]
There are a lot of clever techniques already in play to minimise the amount of data you need to consider.
Still, each triangle's position, shape, and other properties can change each frame, as does that of the camera. So you cannot avoid doing some amount of work for each of the visible triangles and their vertices each frame.
Since you need to update the screen at a consistent frequency (typically 30 or 60 times a second) and the list of triangles that actually need to be rendered each frame is in the millions... Well, that's a lot of work which cannot be avoided.