-
Notifications
You must be signed in to change notification settings - Fork 4
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
Array.permutations() performance #3
Comments
initial PR: #1325 |
@ruslansennov great thanks! It came to my mind if something else might also influence the performance. E.g. did the implementation of the following methods change?
??? Btw - the following part final Array<T> tail = array.tail();
if (tail.isEmpty()) {
return Array.of(array);
} else { could be optimized by if (array.size() == 1) {
return Array.of(array);
} else { |
I'll check all methods
sure :) |
I thought about implementing permutations using Steinhaus–Johnson–Trotter algoritm (https://en.wikipedia.org/wiki/Steinhaus%E2%80%93Johnson%E2%80%93Trotter_algorithm). It is very efficient, as every permutation differs from the previous one by a single swap of two adjacent elements. Guava has a very nice implementation, in a form of generic Iterator depending on a single swap operation (https://github.com/google/guava/blob/master/guava/src/com/google/common/collect/Collections2.java#L652). |
@jest That sounds really nice!! @ruslansennov However, we should double-check that the basic Array operations do not perform worse than in 2.0.6 |
Looking at my benchmark from the Gitter:
and the results:
there seems to be 30% increase of time for some combination of add/remove/map operations. |
@jest interesting, thanks for the benchmarks. We need to take a look why it changed. We recently added some a priori checks in order to
Maybe these checks are responsible for the performance changes. However, it is necessary to do so in order to ensure that essential constraints are valid. The Java converters / views rely on these constraints in order to provide java.util.List impls that behave as expected. But there is another use-case for separating behavior & structure: The 1.0 version of Vavr will internally be completely refactored. My goal is to compensate some of the down-sides of Java's type system that currently force us to repeat slightly changing method declarations. We reach this goal by a new kind of code-generator. I call it "inline code generator". Files contains generated regions (as opposed to protected regions), that are filled automatically with redundant code. Maybe we can benefit here also from selecting appropriate algorithms. |
* improve Array.permutations() performance #1995 * revert to very old algorithm #1995
Thanks. That "inline code generator" would be great to open the decision about performance compromises (e.g. memory-time) to power users that may need them. |
* improve Array.permutations() performance #1995 * revert to very old algorithm #1995
* improve Array.permutations() performance #1995 * revert to very old algorithm #1995
@jest reported performance degradation of
Array.permutations()
invavr:0.9.0
. It seems the problem commit is 9e37950e2fa3113cba6fbcd03feebd1fc86ca1e1Here is (slightly modified for testing) old code:
And here is new code:
The text was updated successfully, but these errors were encountered: