Performance Optimization Techniques
What performance optimization technique is implemented here?
// Before
const values = new Array(1000).fill(0);
values.forEach((_, i) => {
values[i] = heavyComputation();
});
// After
const values = new Array(1000).fill(0);
const chunkSize = 50;
let index = 0;
function processChunk() {
const end = Math.min(index + chunkSize, values.length);
for (; index < end; index++) {
values[index] = heavyComputation();
}
if (index < values.length) {
setTimeout(processChunk, 0);
}
}