Don't initialise null/boolean values in components.
|Reported by:||Freagarach||Owned by:|
Description (last modified by )
In many JS components there are a lot of variables created on init that are not strictly necessary.
this.lastCarriedType = undefined;.
There are more such examples of which some can have more effect on performance. It would be good to not initialise such values, but create them when needed and delete them when not needed anymore. This saves time on init and serialisation data during a game. (Refs. #3834.)
Also booleans are a good example of variables that need not to be initialised.
Some discussion was performed on Phab:rP25119 (text by smiley):
Maybe explicitly defining serializable properties might be cleaner. And if performance is the concern, setting a boolean is definitely faster than deleting properties and re initializing them again. There is also the issue of type optimizations potentially.
Potential performance impacts would depend on the JS engine, but I recall from some earlier benchmark that delete was kinda expensive since further lockups would result in searching the prototype chain. Also, it might change the object layout. Moreover, SM JIT does not play well with delete on arrays and hitting array holes was like hitting a wall. Given the underlying JS array implementation, I would not be surprised if the same behavior was found in objects as well.
I haven't redone those tests in current SM version. So, take that however you will.
Change History (13)
comment:4 by , 23 months ago
|Summary:||Don't initialise null values in components. → Don't initialise null/boolean values in components.|