webapp: speed up encode_and_buffer