some bson encoding optimizations

makes some tests about 10% faster