How would you profile and optimize a Python-based data ingestion script that is suffering from high memory consumption and slow execution times?
Implement optimize_ingestion(records, chunk_size) to process integer records in bounded chunks without copying the complete input. Return a dictionary containing the record count, total value, and largest chunk processed. For example, [1, 2, 3] with chunk_size = 2 returns {"count": 3, "total": 6, "peak_batch": 2}; an empty input returns zero for every field. Assume records is a finite sequence of integers and chunk_size is positive.
def optimize_ingestion(records, chunk_size):