Fixed #23745 -- Improved migrate speed

Of course, commit c7ea633 will not be eventually included, it only serves to measure performance.
The commit this belongs to won't be part of the final patch. @claudep added it for debugging purposes.