alex-plekhanov commented on code in PR #13319:
URL: https://github.com/apache/ignite/pull/13319#discussion_r3579094855
##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java:
##########
@@ -4064,33 +4066,20 @@ private <T> T unmarshalZip(byte[] zipBytes) throws
Exception {
/**
* @param obj Object.
- * @return Bytes.
+ * @return Zip-compressed marshalled bytes.
* @throws IgniteCheckedException If failed.
*/
byte[] marshalZip(Object obj) throws IgniteCheckedException {
assert obj != null;
- return zip(U.marshal(marsh, obj));
- }
-
- /**
- * @param bytes Bytes to compress.
- * @return Zip-compressed bytes.
- */
- private static byte[] zip(byte[] bytes) {
- Deflater deflater = new Deflater();
-
- deflater.setInput(bytes);
- deflater.finish();
+ GridByteArrayOutputStream out = new GridByteArrayOutputStream();
Review Comment:
Do we know average compression level for data, used here? Maybe it's worth
to make reasonable buffer size assumption here (for example `bytes.length / 2`
for 2:1 compression level) to avoid buffer reallocation and copy during resize?
##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java:
##########
@@ -4064,33 +4066,20 @@ private <T> T unmarshalZip(byte[] zipBytes) throws
Exception {
/**
* @param obj Object.
- * @return Bytes.
+ * @return Zip-compressed marshalled bytes.
* @throws IgniteCheckedException If failed.
*/
byte[] marshalZip(Object obj) throws IgniteCheckedException {
assert obj != null;
- return zip(U.marshal(marsh, obj));
- }
-
- /**
- * @param bytes Bytes to compress.
- * @return Zip-compressed bytes.
- */
- private static byte[] zip(byte[] bytes) {
- Deflater deflater = new Deflater();
-
- deflater.setInput(bytes);
- deflater.finish();
+ GridByteArrayOutputStream out = new GridByteArrayOutputStream();
- GridByteArrayOutputStream out = new
GridByteArrayOutputStream(bytes.length);
-
- final byte[] buf = new byte[bytes.length];
-
- while (!deflater.finished()) {
- int cnt = deflater.deflate(buf);
-
- out.write(buf, 0, cnt);
+ // Buffer coalesces ~1KB ObjectOutputStream blocks into fewer JNI
deflate calls.
Review Comment:
Why 1KB? Default BufferedOutputStream buffer size is 8KB
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]