ecs
ecs copied to clipboard
investigate storing filters internally as a bitfield
Currently the world.filters
data structure is key/value pair, where the key is a comma separated list of components. e.g.,
'input,rigidBody,hero': [ entity objects that match the filter ],
Maybe there is value in storing filter key as a bitfield, where each string component name would be mapped into a specific bit in a bitfield.
This module seems pretty good: https://www.npmjs.com/package/bitfield
Additionally I suggest to store filter's content, e.g. list of entitites, and probably world entites list, as a Set
.
Motivation: internally filters are queried oftenly, whis a question like is that entity in this filter
, for which includes
and indexOf
are used, which are O(n). Using the Set
should reduce this to O(logn).
Extra though: probably those internal queries and filter initialization better to move to separate functions, and after that switch their algos to the Set.