You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "Noble Paul (Jira)" <ji...@apache.org> on 2022/02/16 00:25:00 UTC

[jira] [Assigned] (SOLR-14586) replace the second function parameter in Map#computeIfAbsent with static vars

     [ https://issues.apache.org/jira/browse/SOLR-14586?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Noble Paul reassigned SOLR-14586:
---------------------------------

    Assignee:     (was: Noble Paul)

> replace the second function parameter in Map#computeIfAbsent with static vars
> -----------------------------------------------------------------------------
>
>                 Key: SOLR-14586
>                 URL: https://issues.apache.org/jira/browse/SOLR-14586
>             Project: Solr
>          Issue Type: Bug
>            Reporter: Noble Paul
>            Priority: Minor
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> continuing discussion from  SOLR-14579
> consider the following
> {code:java}
> mapObject.computeIfAbsent(key, o -> new HashMap<>());
> {code}
> vs.
> {code:java}
> mapObject.computeIfAbsent(key, Utils.NEW_HASHMAP_FUN)
> {code}
>  
>  The first code fragment is executed as following
> {code:java}
> s.computeIfAbsent(key, new Function() {
>  @Override
>  public Object apply(String key) {
>  return new HashMap<>();
>  }
> }
> {code}
> So, there are two problems with this
>  * A new anonymous inner class is created for that lambda. This one extra class becomes a part of your binary
>  * a new instance of that class is created everytime the {{computeIfAbsent()}} method is invoked, irrespective of whether the value is absent for that key or not. Now imagine that method getting called millions of times and creating millions of such objects for no reason
> OTOH
> when I use {{Utils.NEW_HASHMAP_FUN}}
>  * Only a single anonymous class is created for the entire codebase
>  * Only single instance of that object is created in the VM
> Ideally, we should go all over the codebase and remove such lambdas



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

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