We (Alex and Fande) have had a discussion again on the concerned issue. An alternative way to resolve our problem could be an extra optional flag (MAT_NO_SHRINK_MEMORY) to tell PETSc not to shrink memory at certain stages.
The typical usage would be that we turn this flag on at the beginning of our FormJacobian, and then turn this flag off at the very end of our FormJacobian right before we call MatAssembly(final). We may argue that you should call MatAssembly(final) only once, and then you will be fine. "Call MatAssembly(final) only once" only works in an ideal world. In the real world, we have to manipulate the matrix in a very complicated way to formulate physics.
As always, we are willing to contribute but want to make sure our idea makes sense for you guys before spending time on that.
Thanks,
Fande