Performance concern with let/const
lukeh at microsoft.com
Mon Sep 17 09:49:13 PDT 2012
From: Brendan Eich [mailto:brendan at mozilla.org]
> Allen Wirfs-Brock wrote:
> > As stated above, let isn't the motivator for TDZ, it's const. Let could easily be redefined to not need a TDZ (if that really proved to be a major area of concern). So, you either need to argument against const or argue against block scoping, in general rather let.
> TC39 has been divided on this but managed to reach TDZ consensus.
> Waldemar argued explicitly for TDZ for let, as (a) future-proofing for guards; (b) to enable let/const refactoring without surprises.
> One could argue that (a) can be deferred to let-with-guards, should we add guards. (b) I find more compelling.
That's right - I referenced the original mail with the detailed writeup of the discussion leading to those decisions and the consensus you note. At the time, I raised concerns about performance overhead of TDZ, and I continue to believe it's important to weigh those performance concerns significantly in the discussion about TDZ.
My actual proposal is to remove TDZ for both 'let' and 'const', which addresses the refactoring concern. But it leads to 'const' being observable as undefined, which I expect is the more controversial aspect (though I'm not personally convinced this is a particularly significant practical concern).
More information about the es-discuss