JAX has a great built-in profiler

After reminding myself that you need to add .block_until_ready() for timing purposes, or else it just measures the dispatch time, I got to see that the function was entirely waiting on a “sort” XLA call. By just inserting with jax.profiler.trace("/tmp/jax-trace", create_perfetto_link=True):, you can make this nifty profiler view:

…which is how I found out that just switching from median to mean in a function can speed up results by 100x. All the code was waiting on a “sort”!