I rewrote my canvas library's "reduce-palette" filter last month to make it a lot more code-efficient (because: the library doesn't use web workers, WebGL, etc). But the main reason to go hunting for efficiencies was my (slightly unhinged) decision to do all the color distance calculations in the OKLAB color space.
Demo here: https://scrawl-v8.rikweb.org.uk/demo/filters-027.html