Improve memory usage for large batches