Sort spill
A sort that does not fit in work_mem spills to disk and slows down. EXPLAIN (ANALYZE) shows it as "Sort Method: external merge".
task
work_mem is 64kB, so sorting 20 devices of readings spills to disk. Raise work_mem until the Sort stays in memory.