
Computing Euclidean distance on 144 dimensions
12/18/2020
This post details the engineering challenges and solutions for optimizing the performance of an image matching algorithm used in Cloudflare's CSAM image scanning tool. It analyzes the naive quadratic algorithm, its Euclidean distance calculation in 144 dimensions, and its performance limitations (18 qps). It then explores SIMD (AVX2) optimizations, achieving a 3x improvement but still bottlenecked by memory bandwidth (59 qps). The post discusses the failure of VP-trees due to the curse of dimensionality and introduces a 'short distance' variation that computes a subset of dimensions first, achieving 307 qps by leveraging the application's need to prove non-existence of matches within a threshold.
