Conversation
Previously, synaptic pre/post code had a reference to the `SpikeQueue` which was unique for each run, and was therefore not making use of the cache.
Due to the wrong name, the attribute was not actually fulfilling its documented role. For example, running exactly the same synaptic code twice but with a different number of synapses would not use the cache.
thesamovar
left a comment
There was a problem hiding this comment.
Code looks good but one question I don't understand. Why is SpikeQueue part of a key? And if it should be, why is it enough to only start source start and end as the state of that class? This doesn't seem entirely obvious to me.
Also, is there any way we can add a test suite for this sort of error in the future?
Fully agree that it isn't obvious... We cache functions like
That would be great, but I think we shouldn't do more complex stuff like memory profiling in the general test suite -- we are already running into time outs every now and then. It could be part of #33 ? |
|
Wow, issue #33 was written almost 5 years ago! :) OK that all makes sense. Finishing review now. |
This fixes the memory leak discussed in #933. It turned out that the biggest issue was the way the
SpikeQueuewas handled. Whenever code referenced to theSpikeQueue(allon_pre/on_postcode), then the caching mechanism used an explicit reference to theSpikeQueueas part of the "cache key". This led to two problems:SpikeQueuewas no longer the same.SpikeQueueprevented it from getting garbage collected (since theSpikeQueuestores synaptic delays for each synapse, it can take quite a bit of memory).This was fixed by using our existing mechanism (the
_state_tupleattribute), to replace theSpikeQueuereference by a simple tuple with all information relevant to code generation. I also made the caching mechanism use weak references if possible to avoid the problem in a more general way. There were some other smaller issues (e.g. our_hasheablefunction did not recurse down into tuples) that I fixed as well, together with some minor performance optimisation (which became necessary because the_hasheablefunction is now called more often than before).Performance/memory usage looks pretty good now.
Recreated objects (see #933 for code):

Store/Restore mechanism:

Fixes #933