[ https://issues.apache.org/jira/browse/THRIFT-2368?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
adam updated THRIFT-2368: ------------------------- Description: For applications serializing and deserializing millions of transactions it is important to avoid unnecessary memory allocations - the allocated and abandoned objects needs to be collected and deleted by GC, which creates "stop-the-world" pauses. The new compiler option forces thrift compiler to generate code which is reusing existing objects for deserialization (this is up to caller to make sure that read data will fit). Without that option compiler generates the same code as originally. code generated by original compiler (0.9.1): case 1: // HEADER if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { struct.header = new com.gtech.ngin.ncp.libs.thrift.binary.BinaryHeaderStruct(); struct.header.read(iprot); struct.setHeaderIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 2: // KEYS if (schemeField.type == org.apache.thrift.protocol.TType.SET) { { org.apache.thrift.protocol.TSet _set0 = iprot.readSetBegin(); struct.keys = new HashSet<com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct>(2*_set0.size); for (int _i1 = 0; _i1 < _set0.size; ++_i1) { com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct _elem2; _elem2 = new com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct(); _elem2.read(iprot); struct.keys.add(_elem2); } iprot.readSetEnd(); } struct.setKeysIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; code generated with enabled "java:reuse-objects" option: case 1: // HEADER if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { if (struct.header == null) { struct.header = new com.gtech.ngin.ncp.libs.thrift.binary.BinaryHeaderStruct(); } struct.header.read(iprot); struct.setHeaderIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 2: // KEYS if (schemeField.type == org.apache.thrift.protocol.TType.SET) { { org.apache.thrift.protocol.TSet _set0 = iprot.readSetBegin(); if (struct.keys == null) { struct.keys = new HashSet<com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct>(2*_set0.size); } com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct _elem1 = new com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct(); for (int _i2 = 0; _i2 < _set0.size; ++_i2) { if (_elem1 == null) { _elem1 = new com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct(); } _elem1.read(iprot); struct.keys.add(_elem1); } iprot.readSetEnd(); } struct.setKeysIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; > New option: reuse-objects for Java generator > -------------------------------------------- > > Key: THRIFT-2368 > URL: https://issues.apache.org/jira/browse/THRIFT-2368 > Project: Thrift > Issue Type: New Feature > Components: Java - Compiler > Affects Versions: 0.9.1 > Reporter: adam > Priority: Minor > > For applications serializing and deserializing millions of transactions it is > important to avoid unnecessary memory allocations - the allocated and > abandoned objects needs to be collected and deleted by GC, which creates > "stop-the-world" pauses. The new compiler option forces thrift compiler to > generate code which is reusing existing objects for deserialization (this is > up to caller to make sure that read data will fit). Without that option > compiler generates the same code as originally. > code generated by original compiler (0.9.1): > case 1: // HEADER > if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { > struct.header = new > com.gtech.ngin.ncp.libs.thrift.binary.BinaryHeaderStruct(); > struct.header.read(iprot); > struct.setHeaderIsSet(true); > } else { > org.apache.thrift.protocol.TProtocolUtil.skip(iprot, > schemeField.type); > } > break; > case 2: // KEYS > if (schemeField.type == org.apache.thrift.protocol.TType.SET) { > { > org.apache.thrift.protocol.TSet _set0 = iprot.readSetBegin(); > struct.keys = new > HashSet<com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct>(2*_set0.size); > for (int _i1 = 0; _i1 < _set0.size; ++_i1) > { > com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct > _elem2; > _elem2 = new > com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct(); > _elem2.read(iprot); > struct.keys.add(_elem2); > } > iprot.readSetEnd(); > } > struct.setKeysIsSet(true); > } else { > org.apache.thrift.protocol.TProtocolUtil.skip(iprot, > schemeField.type); > } > break; > code generated with enabled "java:reuse-objects" option: > case 1: // HEADER > if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { > if (struct.header == null) { > struct.header = new > com.gtech.ngin.ncp.libs.thrift.binary.BinaryHeaderStruct(); > } > struct.header.read(iprot); > struct.setHeaderIsSet(true); > } else { > org.apache.thrift.protocol.TProtocolUtil.skip(iprot, > schemeField.type); > } > break; > case 2: // KEYS > if (schemeField.type == org.apache.thrift.protocol.TType.SET) { > { > org.apache.thrift.protocol.TSet _set0 = iprot.readSetBegin(); > if (struct.keys == null) { > struct.keys = new > HashSet<com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct>(2*_set0.size); > } > com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct _elem1 > = new com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct(); > for (int _i2 = 0; _i2 < _set0.size; ++_i2) > { > if (_elem1 == null) { > _elem1 = new > com.gtech.ngin.ncp.libs.thrift.binary.BinaryKeyStruct(); > } > _elem1.read(iprot); > struct.keys.add(_elem1); > } > iprot.readSetEnd(); > } > struct.setKeysIsSet(true); > } else { > org.apache.thrift.protocol.TProtocolUtil.skip(iprot, > schemeField.type); > } > break; -- This message was sent by Atlassian JIRA (v6.1.5#6160)