Optimize Screen Writes
Closed this issue · 0 comments
kilbouri commented
Currently, every frame resets the cursor to the Home position and then outputs every single pixel. This is incredibly slow, since writing to standard output is inherently slow (it is, literally, writing to a virtual file).
One approach to combat this would be to store two sets of buffers: one for the current frame, and one for the previous. Once the current frame is prepared, we iterate over both buffers. If the pixel values are the same, we write nothing. If they differ, then we use an ANSI escape to move our cursor to the exact position it is needed, then write the pixel.