Hi, I think it might be worthwhile require that IndexAmRoutine returned by amhandler are allocated statically. Right now we copy them into local/cache memory contexts. That's not free and reduces branch/jump target prediction rates. For tableam we did the same, and that was actually measurable.
It seems to me like there's not that many index AMs out there, so changing the signature of amhandler() to require returning a const pointer to a const object ought to both be enough of a warning, and not too big a burden. Comments? Greetings, Andres Freund