Tag Archives: performance

Swing dashed line performance

Drawing dashed lines in Swing can be surprisingly slow, and worse, the default implementation seems to be sub-optimal.  Of course, for most apps, this isn’t a big deal, but performance-sensitive apps that draw a lot of dashed lines (or draw them often) can suffer. The first thing to optimize is to only draw the portion […]

Overhead of the modulo operator

While optimizing a number-crunching algorithm, I noticed (almost by accident) that a large amount of time was spent performing modulo/remainder operations (%) used for wrapping around the ends of arrays.  I found that changing i = (i + 1) % n; to i++; while(i >= n) { i -= n; } sped up my code.  […]