kill unused cache preprocessing
Flatten all paths into one array
Second stage of weave optimization

Traverse the paths in C. Not sure it helped though.
Another optimization

Indexing an array is much faster than indexing a matrix.
3.16s to 2.80s on my test.