-
-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List.groupBy performance #1345
Comments
Hi Eirik, thank you for your investigation. Indeed, Javaslang takes at least quadratic time to group the elements. Using a wrapper seems to be a viable option! Greets, |
The problem is mostly that @Override
default <C> Map<C, Iterator<T>> groupBy(Function<? super T, ? extends C> classifier) {
Objects.requireNonNull(classifier, "classifier is null");
if (isEmpty()) {
return HashMap.empty();
} else {
final java.util.Map<C, Collection<T>> results = new java.util.HashMap<>();
for (T value : this) {
final C key = classifier.apply(value);
Collection<T> values = results.get(key);
if (values == null) {
values = new ArrayList<T>();
results.put(key, values);
}
values.add(value);
}
return HashMap.ofAll(results).map((c, ts) -> Tuple.of(c, List.ofAll(ts).iterator()));
}
} which is only |
Very nice! |
@eirikm, @danieldietrich, please review :) |
Hi @danieldietrich! Any reasons why fix for this is not scheduled to be included in a bugfix release? |
@povder no - just overseen it. Thanks for the hint! |
List.groupBy is performing really bad compared to the java.util-counterpart.
I've made a testcase to show the magnitude in difference of performance:
A typical result of running this would be:
kind regards
Eirik Meland
The text was updated successfully, but these errors were encountered: