One thing that might be worth trying would be to isolate the procedure for contracting dims of a tensor and have all fields except counters be `const` in here. That might enable more compiler optimizations