You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by "Yan Zhao (Jira)" <ji...@apache.org> on 2023/07/06 07:11:00 UTC

[jira] [Created] (ZOOKEEPER-4718) Removing unnecessary heap memory allocation in serialization can help reduce GC pressure.

Yan Zhao created ZOOKEEPER-4718:
-----------------------------------

             Summary: Removing unnecessary heap memory allocation in serialization can help reduce GC pressure.
                 Key: ZOOKEEPER-4718
                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4718
             Project: ZooKeeper
          Issue Type: Improvement
          Components: server
    Affects Versions: 3.8.1
            Reporter: Yan Zhao
             Fix For: 3.8.2


In SerializeUtils#serializeRequest, before serializing the request, it always allocates 32 byte array. It's unnecessary; we can allocate the byte array in the catch code block.


{code:java}
    public static byte[] serializeRequest(Request request) {
        if (request == null || request.getHdr() == null) {
            return null;
        }
        byte[] data = new byte[32];
        try {
            data = Util.marshallTxnEntry(request.getHdr(), request.getTxn(), request.getTxnDigest());
        } catch (IOException e) {
            LOG.error("This really should be impossible", e);
        }
        return data;
    }
{code}




--
This message was sent by Atlassian Jira
(v8.20.10#820010)