PERF: improved encoding performance