René's URL Explorer Experiment


Title: Optimise __extends · Issue #9925 · microsoft/TypeScript · GitHub

Open Graph Title: Optimise __extends · Issue #9925 · microsoft/TypeScript

X Title: Optimise __extends · Issue #9925 · microsoft/TypeScript

Description: I was trying to find places to optimise a large project, and realised that the longest running function was actually the __extends call, which prompted me to look at the current code. Current code Two things immediately jumped out at me ...

Open Graph Description: I was trying to find places to optimise a large project, and realised that the longest running function was actually the __extends call, which prompted me to look at the current code. Current code ...

X Description: I was trying to find places to optimise a large project, and realised that the longest running function was actually the __extends call, which prompted me to look at the current code. Current code ...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/9925

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Optimise __extends","articleBody":"I was trying to find places to optimise a large project, and realised that the longest running function was actually the __extends call, which prompted me to look at the current code.\n# Current code\n\nTwo things immediately jumped out at me with the current code:\n\n``` javascript\nvar __extends = (this && this.__extends) || function (d, b) {\n    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n    function __() { this.constructor = d; }\n    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n};\n```\n# Problems\n## Potentially unused code (pre ES5)\n\nThe first problem was that the `__()` function was being created, when it might not be used (though chances of that are probably very small).\n\nThe Solution would be to move the check into an if/else. Related to this is that `null` doesn't have any properties, so the property copying should be in the \"not null\" section.\n\n``` javascript\nvar __extends = (this && this.__extends) || function (d, b) {\n    if (b===null) {\n        d.prototype = Object.create(b);\n    } else {\n        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n        var __=function() { this.constructor = d; };\n        __.prototype = b.prototype;\n        d.prototype = new __();\n    }\n};\n```\n## Inefficient iteration (for ES5+)\n\nThe second problem is purely performance related with the property copying. `for(var p in b)` will iterate over the entire prototype tree, but `if(b.hasOwnProperty(p))` will then skip any that aren't directly on the object/class itself. (see [Enumerability and ownership of properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties))\n\nThe solution would be to use `Object.keys(b)` and iterating an array, which will work only on the object/class itself (and not it's prototype tree), it also automatically skips the same keys we'd be skipping anyway - so taking most of what we're wanting to the browser / native code instead of JS.\n\nUnlike `for...in`, Object.keys fails when called on `null`, `undefined` or any other non-Object, so this requires some extra code to help prevent that happening.\n\nFrom [here](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/keys#Specifications) we see that `Object.keys()` is an ES5+ function.\n\nSuggested code:\n\n``` javascript\nvar __extends = (this && this.__extends) || function (d, b) {\n    if (b instanceof Object) {\n        Object.keys(b).forEach(function(p){\n            d[p] = b[p];\n        });\n        var __=function() { this.constructor = d; };\n        __.prototype = b.prototype;\n        d.prototype = new __();\n    } else {\n        d.prototype = Object.create(null);\n    }\n};\n```\n# Results\n\nIt's very hard to get reliable timings for the code on Chrome Profiling, but on average this looks like roughly a 10% speedup at startup for my project (38 classes in a nested tree up to six deep). There is no major benefit to this, though it does make the code slightly \"safer\".\n\nThe ES5+ code could potentially cause different behaviour if a class tries to inherit from a non-class (such as a number or string), though I'm not sure that is possible to begin with..\n# Language Feature Checklist\n- Syntactic: No changes as this is a compiler change.\n- Semantic: No changes as the final code does the same thing when used as intended (see Results above).\n- Emit: Output code will change depending on ES version needed, both versions are slightly larger than the original.\n- Compatibility: Two versions, one for pre-ES5, most efficient for ES5+\n- Other: There is already an option to prevent __extends being output (which only happens if needed anyway). This could potentially hit older build scripts that manually search & replace the old code.\n","author":{"url":"https://github.com/Rycochet","@type":"Person","name":"Rycochet"},"datePublished":"2016-07-25T10:52:09Z","url":"https://github.com/microsoft/TypeScript/issues/9925"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:aca79df1-f074-241e-5e06-5dfd0d5f7c4c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCEEE:229B2E:847FE6:B14712:6B00DD64
html-safe-nonce385a3081ee445cf345be46cf6533e22b880ca1b4caca32182dc262909112f2c2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRUVFOjIyOUIyRTo4NDdGRTY6QjE0NzEyOjZCMDBERDY0IiwidmlzaXRvcl9pZCI6IjE1MjI0MDY1NDM0NjU3MDA3MDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac376ae36e5020e966566f6a381741be9ce90c8983163d639683a852bec6a05f12
hovercard-subject-tagissue:167338867
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/9925/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f0aedc232250930aa5c099314967ded59183f0ef005ed5ef1385ffc59ec59887/microsoft/TypeScript/issues/9925
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f0aedc232250930aa5c099314967ded59183f0ef005ed5ef1385ffc59ec59887/microsoft/TypeScript/issues/9925
og:image:altI was trying to find places to optimise a large project, and realised that the longest running function was actually the __extends call, which prompted me to look at the current code. Current code ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameRycochet
hostnamegithub.com
expected-hostnamegithub.com
None043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5425dc24e8bd8d6fca9641a12afc984825a43875
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/9925#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F9925
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F9925
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/9925
Reloadhttps://github.com/microsoft/TypeScript/issues/9925
Reloadhttps://github.com/microsoft/TypeScript/issues/9925
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests308 (308)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/9925
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/9925
Optimise __extendshttps://github.com/microsoft/TypeScript/issues/9925#top
Needs More InfoThe issue still hasn't been fully clarifiedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20More%20Info%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/Rycochet
Ryc O'Chet (Rycochet)https://github.com/Rycochet
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issue-167338867
Enumerability and ownership of propertieshttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
herehttps://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/keys#Specifications
https://github.com/yortus
Troy Gerwien (yortus)https://github.com/yortus
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-234974891
https://github.com/Rycochet
Ryc O'Chet (Rycochet)https://github.com/Rycochet
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-234986303
https://github.com/yortus
Troy Gerwien (yortus)https://github.com/yortus
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-234987091
https://github.com/Rycochet
Ryc O'Chet (Rycochet)https://github.com/Rycochet
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-234989894
https://github.com/yortus
Troy Gerwien (yortus)https://github.com/yortus
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-234990021
https://github.com/Rycochet
Ryc O'Chet (Rycochet)https://github.com/Rycochet
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-234990864
https://github.com/yortus
Troy Gerwien (yortus)https://github.com/yortus
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-234991211
https://github.com/Rycochet
Ryc O'Chet (Rycochet)https://github.com/Rycochet
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-234992378
https://github.com/yortus
Troy Gerwien (yortus)https://github.com/yortus
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-234995858
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-234999890
Troy Gerwien (@yortus)https://github.com/yortus
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
Needs More InfoThe issue still hasn't been fully clarifiedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20More%20Info%22
on Jul 25, 2016https://github.com/microsoft/TypeScript/issues/9925#event-733747812
https://github.com/Rycochet
Ryc O'Chet (Rycochet)https://github.com/Rycochet
on Jul 26, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-235196857
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jul 26, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-235316354
https://github.com/Rycochet
Ryc O'Chet (Rycochet)https://github.com/Rycochet
on Jul 26, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-235350051
https://github.com/nin-jin
nin-jin (nin-jin)https://github.com/nin-jin
on Jul 31, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-236420416
https://github.com/nin-jin
nin-jin (nin-jin)https://github.com/nin-jin
on Jul 31, 2016https://github.com/microsoft/TypeScript/issues/9925#issuecomment-236421153
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jul 21, 2020https://github.com/microsoft/TypeScript/issues/9925#event-3572544828
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/9925
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/9925
Needs More InfoThe issue still hasn't been fully clarifiedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20More%20Info%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.