Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
1.8.5
-
None
-
ubuntu 10
Description
I tried Collection.unique
{closure}and it was getting very slow when the dataset grew.
I believe it to be O(n^2)
I have not yet looked it up in the groovy sources,
but I believe that it must be implemented,
like calling that closure over and over again.
I'd like to suggest an alternative implementation,
which actually made things toward O in my case.
like:
Map unique
unique.put(closure(it), it)
return unique.values()
While this might use some more memory,
it really beats the current implementation hands of.
Please note that in this type of implementation,
the closure is only called once per element,
and all the burden of uniquing is placed on the map.
It should be consistent with the contract of the current api.
But it's much faster!
Attachments
Issue Links
- duplicates
-
GROOVY-4606 Exteremely bad performance of .unique() and .unique {closure}
- Open