Open
Description
While we're on the topic of selector optimizations, right now the reason the selectors build up lists of entities and tear them down again is because while most selectors are just simple filters on entities, there are some that aren't, such as FuncSelector
and RandomSelector
.
This sucks, because what I'd like to do is simply (pseudo-code follows):
class Selector:
__init__(self, filter: Callable[Entity, Entity, bool])
self.filter = filter
def evaluate(self, source, entities):
return [e for e in entities if self.filter(source, e)]
and so set operations are basically free:
class AndSelector:
__init__(self, left, right)
self.filter = lambda s, e: left.filter(s, e) and right.filter(s, e)
No intermediate lists at all. As a first guess, this will lead to at least a 2-3x speedup, because selectors like FRIENDLY_MINIONS
do at least 2x the work.
This will require changing the DSL a bit though -- thoughts?