The use of APCs causes at least part of the slowdown observed on macOS. When waiting for all APC calls to be serviced, we invoke my_sleep from dbug_serve_apcs. This sleep is implemented as a call to select() with a valid timeval struct. However on macOS, this select takes longer to return than on Linux. Experimenting with this mechanism leads to show explain for running essentially in the same time as on Linux. However, as far as the test is concerned, it still runs in about 60s on mac (after applying improvements to the waiting mechanism) when on linux it completes in about 5s.
Rather than take a polled approach, we could convert dbug_serve_apcs to use a condition variable as that is supported on both linux and mac.
As an aside, I noticed that my_sleep is supposed to be passed a value in microseconds, but I surmise from usage in our codebase that many callers treat it like it's in milliseconds. I wonder if there are latent bugs as a result.
For now, I'm setting this ticket aside and lowering the priority.
there is
let $wait_condition= select State='show_explain_trap' from information_schema.processlist where id=$thr2;
at the start of show_explain.test before any "invocation" of wait_condition.inc, isn't it?