You are right, we can improve performance here. But maybe in a little bit different way as you suggested.

This looks like a small change but could be very bad regarding
performance. Your change will force us to read every single bit of every file in the working tree. The problem is "m.idEqual(f)" which triggers the computation of sha-1 on the content of the file in the working tree. I would like to avoid computing the id if it is not necessary. E.g. if the last-modification time of the file is the same as we have in the index we know that the file is the same as in the index and for this one we already know the id.

Look at how WorkingTreeIterator.isModified() is used at the end of processEntry(AbstractTreeIterator h, AbstractTreeIterator m, DirCacheBuildIterator i, WorkingTreeIterator f) to see how we could better decide when to overwrite the file or not.