This repository explores approaches to optimize the Just-In-Time (JIT) compilation system in Brian2, a simulator for spiking neural networks. The goal is to reduce compilation overhead while maintaining the ability to share memory between Python and compiled C++ code.
A rough exploration on my end on how current JIT works
Brian2's current runtime mode uses Cython to compile neuron models dynamically. While execution is fast, the compilation process is slow due to massive code expansion - a typical 7,000 character Cython file expands to 535,000 characters of C++ code (76.8× expansion ratio).
I've investigated three main approaches to solve this problem:
- Shared Functions Approach: Extracting common functions into shared include files
- C++ Dynamic Arrays: Implementing C++ dynamic arrays with Python wrappers
- Direct Raw Pointer Access: Exposing raw C++ pointers to the code generator
Based on these experiments, I propose several future directions to further improve Brian2's JIT compilation system.