This simple project demonstrates how to use a web worker to pre-calculate the various spaces in an image that can be filled, in order to fill them immediately when the user clicks on the canvas.
A full description of how this works is written up on My Blog