Revert "Revert "Revert "Revert "Revert "Improve performance of encodeHeader"""""

This reverts commit 3226881bbb2e493c26b910f639d4c95fcb01d225.