-
Enhancement
-
Resolution: Fixed
-
P4
-
fx2.0
-
None
Some of the javafx.scene.shape objects have constructors which take values for their properties and call the setter methods for those properties.
If the values supplied in the constructor happen to match the default values, a property object will be created for the property just to store the default value. This is a waste in those cases. The most obvious example is that the constructor Rectangle(x,y,w,h) may be called with 0 for one or both of x and/or y. Note that there is a Rectangle(w,h) constructor which could be used by a developer if they want x,y to be 0,0, but they may go straight to the xywh constructor out of habit - Rectangle(0,0,winwidth,winheight).
We discussed optimizing setFoo(FooDefault) to avoid creating the property object in the general case, but it wasn't clear this would be valuable since if a developer calls setFoo() they are probably going to be setting it to a non-default value.
But, in the case of constructors, they may supply default arguments out of habit and induce the creation of property objects that aren't really needed with a higher probability than if they called setFoo() intentionally.
Possible solutions:
- live with the extra property objects (granted I haven't measured the hit we might incur from this)
- modify all setFoo() methods to check the value for the default before creating a property object.
- modify just the setFoo() methods we think might end up getting called with a default value to check before creating the object
- modify our internal call sites to do the check, so the setFoo() calls in constructors would check the value before calling the set method
If the values supplied in the constructor happen to match the default values, a property object will be created for the property just to store the default value. This is a waste in those cases. The most obvious example is that the constructor Rectangle(x,y,w,h) may be called with 0 for one or both of x and/or y. Note that there is a Rectangle(w,h) constructor which could be used by a developer if they want x,y to be 0,0, but they may go straight to the xywh constructor out of habit - Rectangle(0,0,winwidth,winheight).
We discussed optimizing setFoo(FooDefault) to avoid creating the property object in the general case, but it wasn't clear this would be valuable since if a developer calls setFoo() they are probably going to be setting it to a non-default value.
But, in the case of constructors, they may supply default arguments out of habit and induce the creation of property objects that aren't really needed with a higher probability than if they called setFoo() intentionally.
Possible solutions:
- live with the extra property objects (granted I haven't measured the hit we might incur from this)
- modify all setFoo() methods to check the value for the default before creating a property object.
- modify just the setFoo() methods we think might end up getting called with a default value to check before creating the object
- modify our internal call sites to do the check, so the setFoo() calls in constructors would check the value before calling the set method