On Sat, 7 Mar 2020 14:11:59 GMT, Kevin Rushforth <k...@openjdk.org> wrote:

>> From what I see, they save the same data.
>
> The anonymous subclasses don't have an instance field for the `bean` or the 
> `name`, so the tradeoff is one of static
> footprint (an extra anonymous inner class) for dynamic footprint (slightly 
> larger instances).
> Note, however, that this savings is reduced by the fact that the inner 
> classes have a `this$0` pointer to the enclosing
> class. I think this means that we are really only saving one reference 
> variable per instance of the anonymous inner
> class versus an instance of SimpleXxxxProperty. That's why I think that in 
> the specific case of this proposed fix, it
> should be fine. I just want to take a closer look.

I ran tests to validate my above assumption, and the results match my 
expectations. Using a `SimpleXxxxxProperty` takes
an extra 8 bytes (one object reference) of storage versus an anonymous inner 
class. I used a null bean and a `this$0`
reference to get the name. I measured it by checking the memory needed for 
1,000,000 instances of an anonymous subclass
of `DoublePropertyBase` objects versus 1,000,000 instances of 
`SimpleDoubleProperty`. The former takes 40 bytes per
instance while the latter takes 48 bytes. This represents a 20% increase in 
memory used.

To see how much this affects the case of the wrapped property objects, I ran 
two tests on the current code and the same
two tests with your proposed fix. The first test creates an 
`ObjectProperty<Double>` object from a `DoubleProperty`
using `DoubleProperty::asObject`. The second test created a `DoubleProperty` 
object from an `ObjectProperty<Double>`
using `DoubleProperty::doubleProperty`.

I got the same results as for the earlier tests: 8 additional bytes (one object 
reference) using `SimpleXxxxProperty`
to create the new wrapped property object. Since these objects are already 
fairly large due to the bidirectional
binding created between the original property and the wrapping property, the 
percentage increase is not all that
great -- about 3.8% in the case of `xxxxProperty`.

| Method | bytes/object current | bytes/object with patch |
| --- | --- | --- |
| DoubleProperty::asObject | 232 | 240 |
| DoubleProperty::doubleProperty | 208 | 216 |

So this begs the question: Do we still want to do this? Is the cleanup worth 
the extra memory used?

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

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

Reply via email to