A fast heuristic to optimize time-space tradeoff for large models