Avoid optimizing if the document is not the same.