How much Wire-compiled proto file is smaller than Protoc-compiled file

nichiyoshi
2 min readMar 19, 2021

When you use Protocol Buffer with Gradle project like Android, major choice of compiler and runtime environment would be either Protobuf Plugin for Gradle by Google (the compiler is called protoc)or Wire Gradle Plugin by Square (the compiler is the same Wire).

In this post from Square, it is said that the method count of compile generated file could be smaller when Wire is used than Google Protobun Plugin for Gradle.

For the Square Register app, generated Protocol Buffer code was taking up a large chunk of our method space. By switching to Wire, we removed almost 10,000 methods from our application and gained a lot of breathing room to add new features.

So in this post, I compared file size between Wire compiler-generated file and protoc compiler-generated file, and also JVM bytecode file size.

File size between Wire compiler-generated file and protoc compiler-generated file

Here is the simple proto file, and I compiled this proto file with Wire and protoc.

syntax="proto3";

option java_package = "com.example.protobufsample";

// This is Person
message Person {
string first_name = 1;
string last_name = 2;
repeated string family_names = 3;
}

The result is, the size of Wire-generated Java file was almost one-third of Protoc-generated Java file.

  • Protoc-generated Person.java: 20K
  • Wire-generated Person.java : 6.4K
  • Wire-generated Person.kt: 5.1K

Wire-generated bytecode could be half size of protoc-generated file

What happens when it is further compiled to JVM bytecode?

  • Class file generated from Protoc-generated Person.java: 17K
  • Class file generated from Wire-generated Person.java : 9.1K
  • Class file generated from Wire-generated Person.kt: 13K

As you can see, the difference was a bit smaller than the comparison between Java files, but still, Wire-generated class file can be half size of Protoc-generated class file.

// Compile to bytecode from Protoc-generated Java file
javac -cp path/to/protobuf-java-VERSION.jar Person.java
// Compile to bytecode from Wire-generated Java file
javac -cp path/to/wire-compiler-VERSION-jar-with-dependencies.jar Person.java
// Compile to bytecode from Wire-generated Kotlin file
kotlinc -jvm-target 1.8 -cp path/to/wire-compiler-VERSION-jar-with-dependencies.jar Person.kt
// note VERSION depends on your environment.

In conclusion, In terms of file size, Wire is better than Protoc, besides, Wire-generated Java/Kotlin file is much readable. So, Wire might be recommended if you use Protocol Buffer with Gradle.

--

--