microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.84k stars 12.46k forks source link

Symbol tables should keep internal properties separate #16868

Closed sandersn closed 5 years ago

sandersn commented 7 years ago

Right now symbol tables store things like __call and __construct alongside user-provided symbols. This forces us to mangle/unmangle symbols that start with two underscores. Instead, symbol tables should keep a map of user-provided symbols as before, but also provide optional properties for internals like __call et al.

When the symbol() type becomes available, the symbol table should also include an "dynamic names" map in addition to the "user-provided names" map.

ahejlsberg commented 7 years ago

In principle I agree, but the challenge here is to make a new representation not consume more memory. We allocate an awful lot of symbol tables (many of them very small), and we wouldn't want to double that number. The advantage of the current representation is that we can put it all in a single map.

RyanCavanaugh commented 5 years ago

Would welcome a PR that shows substantive perf improvement here (seems like the cognitive penalty is reasonably low), but either way this is speculative.