optimize function serialization