-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Optimize performance of maps #10270
Optimize performance of maps #10270
Conversation
👍, logged #10278 |
@ahejlsberg #10298 is an alternative to this and is a port to master of what I was working on for the transforms branch. It has the same improvements in speed and memory usage as this PR but also keeps support for ES3. |
👍 following the discussion in today's design meeting. I've closed #10298 in favor of this. I'll follow up with a separate PR for the isolated cases that should also be switched from |
@@ -1084,7 +1084,7 @@ namespace ts { | |||
|
|||
function internIdentifier(text: string): string { | |||
text = escapeIdentifier(text); | |||
return hasProperty(identifiers, text) ? identifiers[text] : (identifiers[text] = text); | |||
return identifiers[text] || (identifiers[text] = text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could do === undefined
to avoid re-interning ""
from this PR , my project got lots of improvement on compile time and memory used . before : Files: 606 after: Files: 606 Great jobs !!! |
This PR optimizes the compiler's use of objects as maps as follows:
Object.create(null)
. This ensures maps have no prototype (and thus no inherited members).delete
operator to every newly created map object. This causes V8 to put the object in "dictionary mode" and disables creation of hidden classes which are very expensive for objects that are constantly changing shape.hasOwnProperty
calls on property lookups. They're no longer necessary when objects are known to have no prototype.The PR introduces a new
MapLike<T>
type that represents a regular object used as a lookup (e.g. an object literal). AMapLike<T>
requires use ofhasOwnProperty
to determine whether a particular property was inherited from the prototype.The
Map<T>
type now has a brand andMap<T>
instances can only be created by callingcreateMap<T>()
(which in turn callsObject.create(null)
and puts the object into dictionary mode).Performance impact on the Monaco real world code base is as follows:
Definitely a worthwhile optimization, provided we're ok with dropping support for ECMAScript 3 hosts.