RFR: 8264770: BidirectionalBinding should use InvalidationListener to prevent boxing

mstr2 github.com+43553916+mstr2 at openjdk.java.net
Tue Apr 6 15:29:13 UTC 2021


On Tue, 6 Apr 2021 14:29:28 GMT, Nir Lisker <nlisker at openjdk.org> wrote:

> The benchmark might not tell the real story. To test these sorts of performance changes you have to use JMH. There's too much relating to JIT optimizations and JVM startup to be able to rely on the current benchmark.
> The theoretical point about invalidation listeners not boxing in comparison to change listeners is sound, so it won't be worse, but if we are looking for performance metrics, they need to be proper ones.

While true, my main motivation for this issue was that the original code is wrongly implemented because it claims to do one thing, but doesn't do that thing. So it's not primarily a question of optimization, but of correctness of the implementation.

Anyway, here's a comparison benchmark done with JMH:
@State(Scope.Benchmark)
public class BindingBenchmark {
    DoubleProperty property1 = new SimpleDoubleProperty();
    DoubleProperty property2 = new SimpleDoubleProperty();

    public BindingBenchmark() {
        property2.bindBidirectional(property1);
    }

    @Benchmark
    public void benchmark() {
        for (int i = 0; i < 10000000; ++i) {
            property1.set((i % 2 == 0) ? 12345.0 : 54321.0);
        }
    }
}

| Benchmark | Mode | Cnt | Score | Error | Units |
|-----------|------|-----|-------|-------|--------|
| before | thrpt | 5 | 3.455| 0.029 | ops/s |
| after | thrpt | 5 | 10.322 | 0.790 | ops/s |

-------------

PR: https://git.openjdk.java.net/jfx/pull/454


More information about the openjfx-dev mailing list