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

Make most of Message functions non-virtual to reduce generated code size #339

Closed
Tracked by #518
stepancheg opened this issue Sep 22, 2018 · 2 comments
Closed
Tracked by #518
Labels
help-wanted rust-protobuf-v3 Issued to be fixed to release version 3

Comments

@stepancheg
Copy link
Owner

stepancheg commented Sep 22, 2018

Currently, Message has 10 virtual functions which have default implementations which result in increased generated code size.

An example of such function is write_to.

These functions should be non-virtual, and invocable with <M : Message> and &Message.

Possible solutions:

trait Message {
    fn write_to(&self, ...) where Self: Sized { ... }
}

impl dyn Message {
    // copy-paste of above, that's fine
    fn write_to(&self, ...) { ... }
}
  • Add write_to function to MessageExt crate and add MessageExt to crate prelude.

Custom preludes could help here rust-lang/rfcs#890

@stepancheg
Copy link
Owner Author

In master, Message functions are not virtual, but additional MessageDyn trait is introduced for dynamic invocation

@stepancheg
Copy link
Owner Author

This is done in version 3, and won't be ported to branch 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted rust-protobuf-v3 Issued to be fixed to release version 3
Projects
None yet
Development

No branches or pull requests

1 participant