anton-vinogradov commented on code in PR #13319:
URL: https://github.com/apache/ignite/pull/13319#discussion_r3579710387


##########
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:
   We intentionally no longer materialize the uncompressed byte[] (that's the 
whole point of streaming here — cutting peak memory), so `bytes.length` isn't 
available for a ratio-based estimate. marshalZip is also called per-component 
for potentially many small payloads (joiningNodeData via `F.viewReadOnly`), so 
a large fixed initial capacity would over-allocate for the common small case 
and work against the allocation reduction this change targets. 
`GridByteArrayOutputStream` grows by doubling (amortized O(n)), and 
`toByteArray()` returns an exact-sized copy, so pre-sizing wouldn't reduce the 
retained/peak result memory — only the transient resize churn. If you'd still 
like to trim the initial doublings for the large join-data case, I'd rather 
seed a modest fixed capacity (e.g. 512 B, matching DeflaterOutputStream's flush 
chunk) than a ratio of the now-unknown input size. WDYT?



-- 
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]

Reply via email to