简体   繁体   中英

a lot of gc when using parseFrom(inputStream) on Android

Protocol Buffer lite: 2.5.0

When parsing an InputStream on Android I get a lot of gc.
The gc slows the process of receiving data and writing it to a DB a lot - what to do?

GC freed 16514 objects / 714496 bytes in 81ms
GC freed 20570 objects / 888776 bytes in 90ms
GC freed 22768 objects / 908208 bytes in 99ms

File f = new File(Environment.getExternalStorageDirectory().getPath(), "protobuf.dat");
FileInputStream istream = new FileInputStream(f);
FooBar data = FooBar.parseFrom(istream);

The Google-authored Java protobuf implementation is optimized for servers running on OpenJDK/HotSpot/etc., where allocating small short-lived objects is efficient. Dalvik makes different performance trade-offs and may call for a different kind of implementation. Unfortunately, there's not much you can do to make the Google implementation work better (it would probably require a deep re-design), but you could try some of the other Java protobuf implementations listed here to see if any of them perform better:

https://code.google.com/p/protobuf/wiki/ThirdPartyAddOns

In fact, it looks like all of the other Java implementations are explicitly designed for mobile environments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM