Opened 3 years ago
Last modified 2 years ago
#5979 new enhancement
Don't initialise null/boolean values in components.
Reported by: | Freagarach | Owned by: | |
---|---|---|---|
Priority: | Should Have | Milestone: | Backlog |
Component: | Simulation | Keywords: | simple |
Cc: | Patch: | Phab:D3468 |
Description (last modified by )
In many JS components there are a lot of variables created on init that are not strictly necessary.
E.g. in ResourceGatherer
: 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:1 by , 3 years ago
Patch: | → Phab:D3468 |
---|
comment:2 by , 3 years ago
comment:4 by , 3 years ago
Description: | modified (diff) |
---|---|
Summary: | Don't initialise null values in components. → Don't initialise null/boolean values in components. |
comment:9 by , 3 years ago
Description: | modified (diff) |
---|
comment:10 by , 3 years ago
Milestone: | Alpha 25 → Alpha 26 |
---|
comment:11 by , 3 years ago
Keywords: | simple removed |
---|---|
severity: | → simple |
comment:12 by , 3 years ago
Keywords: | simple added |
---|
comment:13 by , 2 years ago
Milestone: | Alpha 26 → Backlog |
---|
In r24993:
Do not initialise null values in cmpGarrisonHolder.
Saves some serialisation data (refs #3834).
Ticket: #5979
Differential revision: Phab:D3468
Comments by: @Angen, @Stan