> On Dec 6, 2015, at 8:57 AM, jeongsik woo <
realja...@gmail.com> wrote:
>
> Hi. I installed node.js 4.2.1(argon).
> I noticed new key 'let' of ES6. (
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Statements/let)
>
> I understood that let use lower memory than 'var'. because let has block scope, but 'var' has function scope.
>
> So I tested memory usage of var and let.
>
> But test result refer to 'var' uses lower memory than 'let'.
> differences of rss, heapTotal, heapUsed value of 'let' is bigger than 'var'.
>
> do I misunderstand 'let'?
>
> Sorry for my english writting, I am english newbie.
>
> below is my test code.
So there's enough complexity in V8 that a microbenchmark like yours may not show off real world scenarios. There are some differences: with `let`, you're making a new variable every time; with `var` you're re-using that. That means that there may be cases that the optimizer could convert back (where the effect won't leak), but those probably have to be written. I don't know the state of that in the optimizer, or if that's even an interesting optimization.
And then there's dead code elimination and all kinds of other optimizer tricks.
Then you've got a tight loop making garbage, and the garbage collector has to run periodically. So that will show a higher RSS, but it may not actually affect a real program unless your real program is at tight loop.
TL;DR: You're probably not measuring what you think you're measuring. if you are measuring that, what you're measuring is likely not relevant to results.
Aria