I suggest the small attached patch that gives a bit of heap_insert() and heap_update() optimization by reducing calls of BufferGetPage(buffer) into them.
I measured call time of these: heap_insert(): avg origin 13394 ns, avg patched 12685 ns; perf increases +5.59% heap_update(): avg origin 15728 ns, avg patched 13936 ns; perf increases +11.39%
This can be notable when there are handling many rows. -- Regards, Andrew K.