3. The column names are cached in the function and do not have to be retrieved each time.
The reason these can't be done by v8 on its own is that they make assumptions that v8 can't guarantee. For the first two, you have to guarantee that the columns array is always the same length. For the first and last, you have to guarantee that the columns will always have the same names.
So even though you take a big hit on the initial eval of the function, you'll likely make up for it by having a better-optimized function.
That might be an improvement, but you probably wouldn't want to use Array.map, which generally has pretty terrible performance. See http://jsperf.com/map-vs-native-for-loop/5
There are three optimizations I see in the eval example:
1. The object is created as a literal rather than by property assignment (see http://jsperf.com/object-literals-vs-object-properties).
2. The for loop loop is unrolled.
3. The column names are cached in the function and do not have to be retrieved each time.
The reason these can't be done by v8 on its own is that they make assumptions that v8 can't guarantee. For the first two, you have to guarantee that the columns array is always the same length. For the first and last, you have to guarantee that the columns will always have the same names.
So even though you take a big hit on the initial eval of the function, you'll likely make up for it by having a better-optimized function.