[
https://issues.apache.org/jira/browse/SOLR-14579?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17141846#comment-17141846
]
Noble Paul commented on SOLR-14579:
-----------------------------------
people misunderstand lambdas
let's look at a very innocuous looking piece of code
{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
> Remove SolrJ 'Utils' generic map functions
> ------------------------------------------
>
> Key: SOLR-14579
> URL: https://issues.apache.org/jira/browse/SOLR-14579
> Project: Solr
> Issue Type: Improvement
> Security Level: Public(Default Security Level. Issues are Public)
> Affects Versions: master (9.0)
> Reporter: Megan Carey
> Priority: Minor
> Time Spent: 1h
> Remaining Estimate: 0h
>
> Remove the map functions like `NEW_HASHMAP_FUN` from the Utils class in solrj
> module to reduce warnings and improve code quality.
> [https://github.com/apache/lucene-solr/blob/master/solr/solrj/src/java/org/apache/solr/common/util/Utils.java#L92]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]