stepancheg / rust-protobuf

Rust implementation of Google protocol buffers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The protobuf library 0.3.0 memory usage is about 300KB higher than 0.28.0

zzzzzzzzzy9 opened this issue · comments

I'm using the open source repository containerd/rust-extensions. When I use protobuf 0.28.0, the memory cost is about 900KB. But when I use protobuf 0.3.0 or 0.4.0, the momory usage is abot 1200KB.
I used the valgrind memory capture tool to collect the memory of the process, and the result is as follows:

  1. for 0.3.0 or 0.4.0
  2. for 0.28.0

By analyzing the results, I found that the function file_descriptor takes up about 300KB of heap memory. This function is in the end of file /src/descriptor.rs. This function was not available in version 0.28.0.

Also, I found that the Message struct in 0.28.0 became the current MessageFull struct, and when I removed the related dependencies of the messageFull struct in the containerd/rust-extensions project (which of course caused the rust-extensions project to not work properly) I noticed that the memory dropped by about 400KB.

I cannot use Message struct in 0.3.0 because of PartialEq.

The differences between 0.28.0(/src/message.rs) and 0.3.0(/src/message.rs and /src/messagedyn.rs):

  1. 0.28.0
    pub trait Message: fmt::Debug + Clear + Any + Send + Sync { .....
  2. 0.3.0
    pub trait Message: Default + Clone + Send + Sync + Sized + PartialEq + 'static {
    pub trait MessageDyn: Any + fmt::Debug + fmt::Display + Send + Sync + 'static {
    We can see that in 0.3.0 static is used in both the Message struct and the MessageDyn struct, but not in 0.28.0

I wonder what the modification of the Message struct and the addition of file_descriptor functions are? Does it really need to be defined as static? This results in an unusually large memory overhead.

Version 0.3 is prehistoric. Current version is 3.x.

Oh, I'm sorry. It is 2.28.0/2.27.1 and 3.3.0/3.4.0. @stepancheg