owlcs/owlapi — pull request #303 by sesuncedu (2014-10-06 02:31:35+00:00)
Title: Use custom set implementation for sets of 2-3 elements

A SmallSet uses 24 bytes, vs 88 bytes for a THashSet with load factor 0.75 with max size 3 (5 element array).

```
Internals before: 756,377,312
Internals after: 697,249,184
```

I have a load of other changes queued up that I need to move into separate feature branches; there are a lot of easy wins - storing a char array in LiteralImplString, instead of a String, can save ~78MB. There are savings from going from utf16 to utf8, but they are dominated by the 20 byte overhead of the array and the 8 byte alignment constraint.

Histogram of top shallow heap size after this change:

Class Name | Objects | Shallow Heap | Retained Heap
------------------------------------------------------------|--------------|--------------------|-----------
char[] | 4,231,480 | 216,306,088 | 216,306,088
uk.ac.manchester.cs.owl.owlapi.OWLAnnotationAssertionAxiomImpl| 4,102,076 | 164,083,040 | 476,978,384
java.lang.Object[] | 58,050 | 109,044,304 | 697,488,328
java.lang.String | 4,231,412 | 101,553,888 | 317,821,888
uk.ac.manchester.cs.owl.owlapi.OWLLiteralImplString | 3,243,649 | 51,898,384 | 296,620,408
java.util.WeakHashMap$Entry | 981,187 | 39,247,480 | 70,649,920
uk.ac.manchester.cs.owl.owlapi.OWLSubClassOfAxiomImpl | 981,144 | 39,245,760 | 39,245,768
java.lang.ref.WeakReference | 981,197 | 31,398,304 | 31,398,304
uk.ac.manchester.cs.owl.owlapi.OWLDeclarationAxiomImpl | 981,175 | 31,397,600 | 31,397,608
uk.ac.manchester.cs.owl.owlapi.OWLClassImpl | 981,151 | 31,396,832 | 31,396,840
org.semanticweb.owlapi.model.IRI | 981,606 | 23,558,544 | 95,900,688
uk.ac.manchester.cs.owl.owlapi.util.collections.SmallSet | 923,877 | 22,173,048 | 22,173,048
java.util.Collections$SingletonSet | 981,176 | 15,698,816 | 15,698,824
uk.ac.manchester.cs.owl.owlapi.OWLAnnotationImpl | 254,289 | 10,171,560 | 10,171,704
java.util.WeakHashMap$Entry[] | 111 | 8,397,616 | 79,047,424
java.util.Collections$SingletonList | 254,288 | 6,102,912 | 16,274,440
gnu.trove.set.hash.THashSet | 57,304 | 2,750,592 | 564,551,200
java.lang.Integer | 20,132 | 322,112 | 322,736
byte[] | 561 | 191,960 | 191,960
java.util.concurrent.ConcurrentHashMap$Node | 3,780 | 120,960 | 533,432
java.lang.Integer[] | 1 | 80,536 | 402,440
java.lang.Object | 3,648 | 58,368 | 58,368
java.util.HashMap$Node | 1,521 | 48,672 | 215,856
java.util.concurrent.ConcurrentHashMap$Node[] | 18 | 35,360 | 568,568
int[] | 396 | 35,024 | 35,024
java.util.HashMap$Node[] | 168 | 22,416 | 235,152
java.lang.Class | 2,693 | 19,936 | 1,282,296
java.net.URL | 244 | 15,616 | 44,264
java.util.LinkedHashMap$Entry | 310 | 12,400 | 66,400
java.lang.reflect.Method | 126 | 11,088 | 27,792
sun.misc.FDBigInteger | 341 | 10,912 | 37,424
com.google.inject.internal.InstanceBindingImpl | 191 | 9,168 | 32,776
Total: 32 of 2,684 entries; 2,652 more | 24,268,356 | 905,714,512 |