Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[proposal] Pigeon should use Protobuf to share data between "HostApi" and "FlutterApi" #60758

Open
iapicca opened this issue Jul 2, 2020 · 3 comments
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter p: pigeon related to pigeon messaging codegen tool P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team

Comments

@iapicca
Copy link
Contributor

iapicca commented Jul 2, 2020

Hi all,
the following proposal is largely inspired by this great article from @truongsinh

Use case

Common issues with platform channel data transfer:

  • FlutterStandardTypedData issues
  • often require to cast data
  • frequent loss of type-safety
  • loss of performance with List, Map<String,dynamic>

Proposal

Use protobuf as default for pigeon's platform channel communication.

Extras

  • grpc uses protobuf, the proposed implementation
    would make very easy to cache data on native side from a grpc client

  • AFAIK flutterfire uses a grpc client on the native side
    the proposed implementation should lead to better performance and stability

cc @gaaclarke as requested in the feedback tab of pigeon readme

Thank you

@iapicca iapicca added c: new feature Nothing broken; request for a new capability plugin package flutter/packages repository. See also p: labels. c: proposal A detailed proposal for a change to Flutter p: pigeon related to pigeon messaging codegen tool labels Jul 2, 2020
@iapicca iapicca changed the title [proposal] Pigeon should use Protobuf to share data between Platform (like all other plugins for the matter) [proposal] Pigeon should use Protobuf to share data between "HostApi" and "FlutterApi" Jul 2, 2020
@gaaclarke
Copy link
Member

Thanks @iapicca are you saying you want to be able to write in protobuf language, or you want pigeons to serialize in a binary format that is compatible with protobufs? You've listed problems with platform channels, but what are the problems you are trying to address in pigeon?

Protobufs were designed to help with network throughput which means they were optimized for size compression not speed of serialization / deserialization. That means protobufs aren't well suited for situations where there is no network communication. Also, since pigeons are ephemeral they can be optimized for speed by removing that feature. On the other hand, Protobufs can be saved and reloaded with versioning, at a cost.

The parser for pigeon is split into a frontend and a backend so that either of them could be replaced. We had things like protobufs in mind when we designed it and it isn't out of the cards.

@iapicca
Copy link
Contributor Author

iapicca commented Jul 6, 2020

Hi @gaaclarke
first of all thank you for reading through my proposal,
in the back of my head I took for granted that protobuf was optimized for serialization,
this not being the case makes sense to prefer pigeons for speed over size;
nonetheless given your comment

[...] or you want pigeons to serialize in a binary format that is compatible with protobufs?

a compatibility between pigeon and protobuf sounds great
and having the option to use protobuf with pigeon,
maybe through a TypeAdapter could be desirable

Anyway those are just my 2 cents,
this solution being considered is all I ask for.

Thanks again for your answer

@Sunbreak
Copy link
Contributor

Interesting proposal.

But I would recommand dart:ffi or https://github.com/dart-native/dart_native if performance is a concern

@flutter-triage-bot flutter-triage-bot bot added P3 Issues that are less important to the Flutter project and removed P6 labels Jun 28, 2023
@flutter-triage-bot flutter-triage-bot bot added team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team labels Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter p: pigeon related to pigeon messaging codegen tool P3 Issues that are less important to the Flutter project package flutter/packages repository. See also p: labels. team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team
Projects
None yet
Development

No branches or pull requests

5 participants