This was done in the context of #25284 , but I think it also makes sense standalone.
The basic idea is that serialization type should not be initialized when it is not needed. Same for the serialization version.
So do this here for HashWriter
. CHashWriter
remains in places where it is not yet possible.