{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2734","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2734/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2734/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2734/events","html_url":"https://github.com/Microsoft/TypeScript/pull/2734","id":67958965,"number":2734,"title":"Use a single scanner for all parsing tasks.","user":{"login":"CyrusNajmabadi","id":4564579,"avatar_url":"https://avatars.githubusercontent.com/u/4564579?v=3","gravatar_id":"","url":"https://api.github.com/users/CyrusNajmabadi","html_url":"https://github.com/CyrusNajmabadi","followers_url":"https://api.github.com/users/CyrusNajmabadi/followers","following_url":"https://api.github.com/users/CyrusNajmabadi/following{/other_user}","gists_url":"https://api.github.com/users/CyrusNajmabadi/gists{/gist_id}","starred_url":"https://api.github.com/users/CyrusNajmabadi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyrusNajmabadi/subscriptions","organizations_url":"https://api.github.com/users/CyrusNajmabadi/orgs","repos_url":"https://api.github.com/users/CyrusNajmabadi/repos","events_url":"https://api.github.com/users/CyrusNajmabadi/events{/privacy}","received_events_url":"https://api.github.com/users/CyrusNajmabadi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/cla-not-required","name":"cla-not-required","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-04-12T21:08:07Z","updated_at":"2015-04-12T21:35:21Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/2734","html_url":"https://github.com/Microsoft/TypeScript/pull/2734","diff_url":"https://github.com/Microsoft/TypeScript/pull/2734.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/2734.patch"},"body":"Our current \"nested function\" style of coding comes with a cost.  Specifically, calling the outer functions causes a large amount of engine cost to intialize all the inner functions contained within.  This is problematic for certain functions (like parsing and scanning) as we call them for every file, and thus take that hit over and over.  \r\n\r\nOne solution to this is to use classes.  Classes initialize their instance functions only once, storing them on the prototype.  From that point on, all new instances get those initialized functions from the prototype.  However, we have decided to avoid classes, and consistently use functions instead.\r\n\r\nAl alternate, non-class, approach is to move to singletons.  Instead of creating a new scanner or parser for each source file, instead we just create one, and reuse it for each file.  This is simple to implement, and fits well with our current function-style approach."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/92136005","html_url":"https://github.com/Microsoft/TypeScript/pull/2734#issuecomment-92136005","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2734","id":92136005,"user":{"login":"DanielRosenwasser","id":972891,"avatar_url":"https://avatars.githubusercontent.com/u/972891?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielRosenwasser","html_url":"https://github.com/DanielRosenwasser","followers_url":"https://api.github.com/users/DanielRosenwasser/followers","following_url":"https://api.github.com/users/DanielRosenwasser/following{/other_user}","gists_url":"https://api.github.com/users/DanielRosenwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRosenwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRosenwasser/subscriptions","organizations_url":"https://api.github.com/users/DanielRosenwasser/orgs","repos_url":"https://api.github.com/users/DanielRosenwasser/repos","events_url":"https://api.github.com/users/DanielRosenwasser/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRosenwasser/received_events","type":"User","site_admin":false},"created_at":"2015-04-12T21:35:21Z","updated_at":"2015-04-12T21:35:21Z","body":"I see now - you're closing over the core state and modifying that at each call to `parse`. That's pretty nifty."}}