Revert part of change in #7466 to fix issue because encoder is not threadsafe so cannot be shared