Rectangle detection is the most CPU consuming part of the process. WASM should be used for that to get a pretty significant performance boost.