time ./jsc -e "function e() { for (var i = 0; i < 99999999; ++i) { } } e();" real 0m0.389s user 0m0.367s sys 0m0.009s time ./jsc -e "function e() { var a = 0; for (var i = 0; i < 99999999; ++i) { } } e();" real 0m0.325s user 0m0.312s sys 0m0.009s It seems like something has to be going wrong for this to be the case. Using 64 bit trunk jsc, r40951, on a 2GHz Core 2 Duo MacBook.
This may be due to cache effects.
time /WebKitBuild/Release/jsc -e "function e() { var a = 0; for (var i = 0; i < 99999999; ++i) { } } e();" real 0m0.300s user 0m0.293s sys 0m0.006s time /WebKitBuild/Release/jsc -e "function e() { for (var i = 0; i < 99999999; ++i) { } } e();" real 0m0.301s user 0m0.293s sys 0m0.006s This doesn't reproduce for me. As Mark says, this kind of effect can be caused by cache effects as stack layout changes, and is not necessarily unexpected. We don't currently optimize to remove unused variables; we could do so, but every additional optimization pass comes at a runtime cost in JIT, and we would only want to do so if there is a demonstrable value in doing so (real programs tend not to declare lots of unused variables, and as your numbers show, it's not necessarily a performance regression even if they do!) I don't think there is anything we need to fix here.