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

Moderately-sized crate with protobuf-generated modules takes 5 minutes to compile in release mode #383

Closed
ancwrd1 opened this issue Jan 29, 2019 · 5 comments

Comments

@ancwrd1
Copy link

ancwrd1 commented Jan 29, 2019

I am not sure whether this issue relates to Rust compiler itself or to the generated code but the problem I experience is that the crate which contains just around 36 protobuf files of various sizes takes 5 minutes to compile in release mode, with rustc compiler memory usage maxing at 1.5Gb of RAM.
The number of files will be probably growing further so the build times will increase even more.

Considering that it takes just about 1.5-2x times as much to build the rest of the crates (more than 300 dependencies currently) there is something wrong with the generated protobuf code, either it's too complicated or too large.

@stepancheg
Copy link
Owner

One of the possible causes of this is this issue: #339: each generated message has too many virtual functions. I'm not sure how much it affects compilation performance, but it definitely bloats the resulting binary size.

I have not found a good solution for this issue with the current Rust language. Ideas are welcome.

@ancwrd1
Copy link
Author

ancwrd1 commented Feb 2, 2019

Are all of the generated reflection methods (descriptor methods returning or implementing protobuf::reflect::xxx) strictly necessary for (de)serialization? I am wondering if they can be made optional as it seems they add quite a bit to the code and perhaps compilation performance.

@stepancheg
Copy link
Owner

Reflection is also used for printing to text format (e. g. for debugging). Technically it's possible to make it optional, but I have a feeling that largest code size is occupied by unnecessary virtual functions of Message trait. Hint: try nm your-binary | grep protobuf.

Also, FYI, for primitive fields, I tried to rewrite reflection implementation to store field offsets instead of generating accessor functions. AFAIR, it did not save a lot. However, it can probably speed up compilation. I'll try to revive that patch.

@stepancheg
Copy link
Owner

OK, switching to offsets saves only about 3% of generated code size.

@stepancheg
Copy link
Owner

Closing due to old age.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants