Skip to content

true private members & symbols ? #13879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ichiriac opened this issue Feb 4, 2017 · 5 comments
Closed

true private members & symbols ? #13879

ichiriac opened this issue Feb 4, 2017 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@ichiriac
Copy link

ichiriac commented Feb 4, 2017

Hi,

Is there any reason you don't use symbols for private properties on classes ? I'm really interested on what you have done with typescript and try something similar so I'm maybe missing something.

Best Regards,
Ioan

@ichiriac
Copy link
Author

ichiriac commented Feb 4, 2017

BTW, I've read all thread on Stackoverflow http://stackoverflow.com/questions/12713659/typescript-private-members and Codeplex https://typescript.codeplex.com/discussions/397651 but they don't speak about symbols so maybe they are too old as symbols were introduced lately.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Feb 4, 2017
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Feb 4, 2017

We once got a PR from @Arnavion (see #684), however, the emit has some issues.

At the time, @NoelAbrahams noted:

  • Class instantiation is about 60% slower when using symbols.
  • Property and method access is about 90% slower when using symbols.
  • The codegen when using symbols is not minification-friendly; even advanced optimisation will not minify string literals such as __symbol("_property_p");

Things might have changed in terms of speed, but at this point I'd rather we didn't change our private emit until we see the direction ECMAScript takes with the private slots proposal. In fact, I don't think our public, private, or protected modifiers should have any sort of impact on emit.

@ichiriac
Copy link
Author

ichiriac commented Feb 4, 2017

Hi @DanielRosenwasser,

Many thanks, it's very helpfull all these links. Finger crossed for private slots, anyway they already reserved the private keyword http://www.ecma-international.org/ecma-262/6.0/#sec-future-reserved-words

@Yogu
Copy link
Contributor

Yogu commented Feb 14, 2017

Class instantiation is about 60% slower when using symbols.
Property and method access is about 90% slower when using symbols.

Seems no longer to be true, property access is 2% slower and instanciation performance is equal for me (Chrome 56). By the private slot proposal, do you mean the tc39 proposal-private-fields?

@ichiriac
Copy link
Author

ichiriac commented Feb 14, 2017

Sadly, symbols will not be a guarantee to make things fully private : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols

Not tested yet, but seems obviously slow, is to use : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants