Hi, does anyone know why adding instance variables is so slow?
I did some quick benchmarks (see below), resulting in more than order of magnitude speed difference between having it in the class definition and adding it later. In fact it is still much faster to delete the class and then recreate it with the instance variables in the d efinition. For four arguments it is till 8x faster to delete the class four times and recreate it then just add the variable. Unfortunately I cannot just trash the classes (they have methods and inheritance). So the question is: why is it so slow? can I somehow improve the performance? Thanks, Peter Benchmarks: [ cls := Object subclass: #Some1. cls removeFromSystem. ] bench. "'91 per second'" [ cls := Object subclass: #Some2 instanceVariableNames: 'variable'. cls removeFromSystem ] bench. "'90 per second'" [ cls := Object subclass: #Some3. cls addInstVarNamed: 'variable'. cls removeFromSystem. ] bench. "'7 per second'" [ cls := Object subclass: #Some4. cls removeFromSystem. cls := Object subclass: #Some4 instanceVariableNames: 'variable'. cls removeFromSystem. ] bench. "'43 per second'" [ cls := Object subclass: #Some3. cls addInstVarNamed: 'variable1'. cls addInstVarNamed: 'variable2'. cls addInstVarNamed: 'variable3'. cls addInstVarNamed: 'variable4'. cls removeFromSystem. ] bench. "'2 per second'" [ cls := Object subclass: #Some4. cls removeFromSystem. cls := Object subclass: #Some4 instanceVariableNames: 'variable1 variable2 variable3 variable4'. cls removeFromSystem. ] bench. "'44 per second'" [ cls := Object subclass: #Some5. cls removeFromSystem. cls := Object subclass: #Some5 instanceVariableNames: 'variable1'. cls removeFromSystem. cls := Object subclass: #Some5 instanceVariableNames: 'variable1 variable2'. cls removeFromSystem. cls := Object subclass: #Some5 instanceVariableNames: 'variable1 variable2 variable3'. cls removeFromSystem. cls := Object subclass: #Some5 instanceVariableNames: 'variable1 variable2 variable3 variable4'. cls removeFromSystem. ] bench. "'17.269 per second'"