This is a backport for #30188, but in 5.3.x we'll simply revert the optimization from 9624ea392aa1a97f3e52f383e9c62ac3c84c04eb.