RFR: 8240692: Cleanup of the javafx property objects

Jeanette Winzenburg fastegal at openjdk.java.net
Mon Mar 16 12:49:55 UTC 2020


On Sun, 15 Mar 2020 20:48:57 GMT, Nir Lisker <nlisker at openjdk.org> wrote:

>> 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?
>
>> So this begs the question: Do we still want to do this? Is the cleanup worth the extra memory used?
> 
> I'm not sure. This raises the opposite question: are there any places where we can benefit from introducing anonymous
> classes instead of the current implementation?
> In my own code, I prefer the readability and conciseness over performance. However, since JavaFX is a library, we might
> want to go with the performance route. I don't know how important the memory consumption is for users in this case or
> the other similar cases.

Just playing devil's advocate :)

Technically, there's a functional difference between the inline extension and useage of SimpleXX: in the former,
getName returns the current name of mapped property, in the latter it returns its name at the time of creating the
mapped property.

Afaics, there is nothing in the spec of getName that prevents custom implementations with name (and bean) being mutable
(the SimpleXX have implemented them immutable, but then they are only default implementations). Not that I can imagine
any use-case for it, but if they exist, the new mappings might break existing code.

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

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


More information about the openjfx-dev mailing list