-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Description
(Capturing from offline discussion for tracking, and to capture further discussion in one place.)
Currently Pigeon serializes objects as dictionaries where the keys are string versions of the field name, and the value is the value. This is a common way to do manual platform channel serialization because it's the most intuitive to maintain, but it's extremely inefficient (as discussed some here). A more efficient approach is to just serialize the fields as an array; unlike doing it by hand, the fact that you have to do index-matching across languages (which is very error-prone to maintain, as well as confusing to read, when done manually) is a non-problem with Pigeon, because it's all generated code that people don't need to read as a normal part of plugin maintenance. And since Pigeon isn't a multi-version-compatible system, but requires that both sides be generated with the same pigeon version, we don't get any runtime advantage from the string keys.
We should change all of the dictionary serialization to array-based serialization (as is already done for function arguments). Most importantly object serialization, but we should also do it for responses (currently they use a dictionary, while the corresponding Flutter-level method channel system uses an array and just looks at the length of the array to know if it's an error or success, which we can also do).
In discussions, @gaaclarke has suggested that we should implement a handshake during API setup to guarantee that the two sides of the channel are using the same version of Pigeon. I think that's a nice-to-have, but not a blocker for adopting this, since it's already the case that mismatched Pigeon versions can blow up in surprising ways.
/cc @tarrinneal