You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-issues@hadoop.apache.org by "hfutatzhanghb (via GitHub)" <gi...@apache.org> on 2025/02/08 02:13:02 UTC

Re: [PR] HADOOP-19377. Avoid initialize useless HashMap in protocolImplMapArray. [hadoop]

hfutatzhanghb commented on PR #6927:
URL: https://github.com/apache/hadoop/pull/6927#issuecomment-2644432659

   > Hello @hfutatzhanghb . I'm a little unclear on the intent of this patch. It seems a constant is being renamed, but see an actual change in the initialization logic.
   > 
   > If the intent is to somehow avoid the `new HashMap<>(10)` calls, I imagine the intent is to pre-allocate space in the structure for a few expected protocols. This might not actually be useless if it's keeping allocation of the hash table small, but also pre-allocating enough to avoid dynamic re-allocation later.
   
   @cnauroth Sir, thanks for your reviewing. 
   `final static short MAX_SIZE = RPC_PROTOCOL_BUFFER.value`,  the value of MAX_SIZE is 3 and we have three RpcKind in RPC_PROTOCOL_BUFFER.
   But we initialize 4 hashmaps and add them to protocolImplMapArray.
   The fourth hashmap in protocolImplMapArray will be never used.
   ```java
      Map<ProtoNameVer, ProtoClassProtoImpl> getProtocolImplMap(RPC.RpcKind rpcKind) {
        if (protocolImplMapArray.size() == 0) {// initialize for all rpc kinds
          for (int i = 0; i < RpcKind.MAX_SIZE; ++i) {
            protocolImplMapArray.add(
                new HashMap<ProtoNameVer, ProtoClassProtoImpl>(10));
          }
        }
        return protocolImplMapArray.get(rpcKind.ordinal());   
      }
   ```
   
   Hope to receive your response, Sir. thanks again.


-- 
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: common-issues-unsubscribe@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-issues-help@hadoop.apache.org