Perf: Move chunkloading instrumentation to separate function (#91382)
## What?
The chunkloading instrumentation causes a GC root because of writing to
`globalThis.__next_require__` / `globalThis.__next_chunk_load__`.
Splitting it into a separate function reduces the scope being retained
in memory.
Switch onHeaders to use for loop which is faster.