项目作者: diffbot

项目描述 :
Memory-efficient Protocol Buffers Java code generator with primitive arrays
高级语言: Java
项目地址: git://github.com/diffbot/primibuf.git
创建时间: 2021-02-02T00:04:28Z
项目社区:https://github.com/diffbot/primibuf

开源协议:

下载


PrimitiveBuffers - Fast Protocol Buffers with Primitive Arrays

PrimitiveBuffers is a Java implementation of the Google’s Protocol Buffers v3
that has been developed for low memory footprint use cases.
Currently it only supports decoding and readonly.

The default Protobuf Java library uses generic List for repeated fields, including primitive types.
For example, it would use List<Integer> for a repeated int32 fields.
Compared to the primitive array int[], List<Integer> needs lots of wrapper objects that requires
more memory and thus more GC activity.
This library uses primitive arrays as much as possible to reduce the overhead.

It has been used in production in Diffbot entity linking system and brings the GC down significantly.

Gabage Collection activity on a production server

Usage

Overall, we tried to keep the public API as close to Google’s Protobuf-Java as possible,
so most use cases should require very few changes.

In your build.gradle:

  1. repositories {
  2. maven { url "https://maven.pkg.github.com/diffbot/primibuf" }
  3. }
  4. dependencies {
  5. implementation 'com.diffbot.primibuf:primibuf-runtime:0.3'
  6. }
  7. protobuf {
  8. protoc {
  9. artifact = 'com.google.protobuf:protoc:3.5.1'
  10. }
  11. plugins {
  12. primibuf {
  13. artifact = 'com.diffbot.primibuf:primibuf-generator:0.3:protoc@jar'
  14. }
  15. }
  16. generateProtoTasks {
  17. all().each { task ->
  18. task.builtins { }
  19. task.plugins {
  20. primibuf {
  21. outputSubDir = 'java'
  22. }
  23. }
  24. }
  25. }
  26. }

Limitations

  • Only protobuf 3 is officially supported
    • We don’t support custom default value

Acknowledgement

The library was forked from https://github.com/HebiRobotics/QuickBuffers.