-
Enhancement
-
Resolution: Unresolved
-
P4
-
fx2.0
There is a significant opportunity to reduce the amount of memory used at runtime in Fx by replacing boolean fields (not properties) with bit fields. I ran the following expression on Node, Parent and NGNode. Bit fields are only worth it if there are many instances. What other classes have many instances in Fx.
package test;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import com.sun.javafx.sg.prism.*;
import javafx.scene.*;
public class Fields {
public static void main(String[] args) {
int fieldCount = 0, nonStaticCount = 0, boolCount = 0;
Class clazz = NGNode.class;
while (clazz != null) {
Field[] fields = clazz.getDeclaredFields();
fieldCount += fields.length;
for (Field field : fields) {
int mod = field.getModifiers();
if (!Modifier.isStatic(mod)) {
nonStaticCount++;
if (field.getType() == boolean.class) {
System.out.println("Field name = " + field.getName());
System.out.println("\tField type = " + field.getType().getName());
boolCount++;
}
}
}
clazz = clazz.getSuperclass();
}
System.out.println("Number of fields = " + fieldCount + " non-static = " + nonStaticCount);
System.out.println("Number of non-static booleans = " + boolCount + ", " + (100 * (boolCount / (double) nonStaticCount) + "%"));
}
}
package test;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import com.sun.javafx.sg.prism.*;
import javafx.scene.*;
public class Fields {
public static void main(String[] args) {
int fieldCount = 0, nonStaticCount = 0, boolCount = 0;
Class clazz = NGNode.class;
while (clazz != null) {
Field[] fields = clazz.getDeclaredFields();
fieldCount += fields.length;
for (Field field : fields) {
int mod = field.getModifiers();
if (!Modifier.isStatic(mod)) {
nonStaticCount++;
if (field.getType() == boolean.class) {
System.out.println("Field name = " + field.getName());
System.out.println("\tField type = " + field.getType().getName());
boolCount++;
}
}
}
clazz = clazz.getSuperclass();
}
System.out.println("Number of fields = " + fieldCount + " non-static = " + nonStaticCount);
System.out.println("Number of non-static booleans = " + boolCount + ", " + (100 * (boolCount / (double) nonStaticCount) + "%"));
}
}