Performance concern with let/const

Andreas Rossberg rossberg at google.com
Tue Sep 18 04:27:09 PDT 2012


On 17 September 2012 19:51, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>
> On Sep 17, 2012, at 12:37 PM, Luke Hoban wrote:
>>
>> These are good questions.  Paul will be attending the TC39 meeting this week, and can likely talk to specific details.   High level though, we statically eliminate the TDZ checks for references to 'let' within the same closure body as the declaration.
>>
>
> The other major check that I would expect to be significant, is whether a inner function that references an outer TDZ binding is (potentially) called before initialization of the binding.  EG:
>
> {
>     function f(){return x}
>     f();   //TDZ check of x in f can not be eliminated
>     let x=1;
> }
>
> {
>     function f(){return x}
>     let x=1;  //TDZ check of x in f should be eliminated
>     f();
> }

Unfortunately, detecting this case in general requires significant
static analysis, since f might be called indirectly through other
functions (even ignoring the case where f is used in a first-class
manner).

/Andreas


More information about the es-discuss mailing list