Skip to content

Optimize format of type list id strings used in maps #10240

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

Merged
merged 1 commit into from
Aug 11, 2016

Conversation

ahejlsberg
Copy link
Member

The compiler extensively uses caches to share instantiations of generic types as well as union, intersection, and tuple types. These caches are simply objects where the entries are keyed by property names synthesized from the unique IDs assigned to type objects. Previously we'd construct type cache keys as comma separated lists of type IDs. For example, the union type A | B | C | D would have a key like "1000,1001,1002,1003", where each numeric string is the unique ID of the type. This PR optimizes the key format by encoding two or more consecutive IDs as "xxxx:nnnn", where xxxx is the starting ID and nnnn is the number of IDs. So, the key for A | B | C | D simply becomes "1000:4" if the types have consecutive IDs. Since union types often have constituents with consecutive IDs (particularly union enum types), this can dramatically reduce the length of keys, which helps performance and memory consumption. Informal tests show a 2-3% speedup of the type check phase when compiling the compiler itself.

@weswigham
Copy link
Member

Almost a kind of run length encoding for IDs. Neat.

@ahejlsberg ahejlsberg merged commit e00ce94 into master Aug 11, 2016
@ahejlsberg ahejlsberg deleted the optimizeTypeListIds branch August 11, 2016 17:11
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants