Optimized canonical serialization formula.