ecs icon indicating copy to clipboard operation
ecs copied to clipboard

investigate storing filters internally as a bitfield

Open mreinstein opened this issue 3 years ago • 1 comments

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

mreinstein avatar Jul 12 '21 17:07 mreinstein

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.

pavelvasev avatar Jul 24 '21 05:07 pavelvasev