In NuPIC the TM does what you’re talking about, by using the
Connections class. The connections class keeps a list of input axons and where all of their synapses go to, and it efficiently distributes each active input by iterating through just the synapses which the input connects to.
The SP does not use the connections class, instead using sparse matrices. In the community fork I’ve changed the SP to use the connections class and also optimized the connections class.