René's URL Explorer Experiment


Title: `~lib/array/Array#push` is unnecessarily garbage-y · Issue #1798 · AssemblyScript/assemblyscript · GitHub

Open Graph Title: `~lib/array/Array#push` is unnecessarily garbage-y · Issue #1798 · AssemblyScript/assemblyscript

X Title: `~lib/array/Array#push` is unnecessarily garbage-y · Issue #1798 · AssemblyScript/assemblyscript

Description: In a benchmark I discovered that AssemblyScript is significantly slower than JavaScript when using --runtime incremental when filling Arrays. Language Runtime Average vs JS JavaScript 233.68ms 1.0x AssemblyScript stub 345.35ms 1.5x Assem...

Open Graph Description: In a benchmark I discovered that AssemblyScript is significantly slower than JavaScript when using --runtime incremental when filling Arrays. Language Runtime Average vs JS JavaScript 233.68ms 1.0x...

X Description: In a benchmark I discovered that AssemblyScript is significantly slower than JavaScript when using --runtime incremental when filling Arrays. Language Runtime Average vs JS JavaScript 233.68ms 1.0x...

Opengraph URL: https://github.com/AssemblyScript/assemblyscript/issues/1798

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`~lib/array/Array#push` is unnecessarily garbage-y","articleBody":"In a benchmark I discovered that AssemblyScript is _significantly_ slower than JavaScript when using `--runtime incremental` when filling Arrays.\r\n\r\nLanguage | Runtime | Average | vs JS\r\n-- | -- | -- | --\r\nJavaScript |   | 233.68ms | 1.0x\r\nAssemblyScript | stub | 345.35ms | 1.5x\r\nAssemblyScript | minimal | 354.60ms | 1.5x\r\nAssemblyScript | incremental | 18758.50ms | 80.3x\r\n\r\n\r\nA `d8` trace revealed the following profile:\r\n\r\n```\r\n[Bottom up (heavy) profile]:\r\n  ticks parent  name\r\n  18670   96.1%  /usr/lib/system/libsystem_platform.dylib\r\n  13530   72.5%    Function: *~lib/rt/itcms/__renew\r\n  13530  100.0%      Function: *~lib/array/ensureSize\r\n  13530  100.0%        Function: *~lib/array/Array#push\r\n  13530  100.0%          Function: *binaryheap_optimized/BinaryHeap#push\r\n  13530  100.0%            Function: *binaryheap_optimized/push\r\n   5119   27.4%    Function: *~lib/rt/itcms/__new\r\n   5119  100.0%      Function: *~lib/rt/itcms/__renew\r\n   5119  100.0%        Function: *~lib/array/ensureSize\r\n   5119  100.0%          Function: *~lib/array/Array#push\r\n   5119  100.0%            Function: *binaryheap_optimized/BinaryHeap#push\r\n```\r\n\r\nwhich led me to investigate the `Array#push()` [implementation](https://github.com/AssemblyScript/assemblyscript/blob/42c2dbc987c2e9f4096a226b62bbf0e72b4a0e51/std/assembly/array.ts#L204-L216), which calls`ensureSize()`. `ensureSize()` will create a new buffer with exactly one slot more if the previous buffer was full. This means that once you ran out of capacity once, every subsequent call to `push()` will create a new buffer copy all the data to the new buffer and create work for the garbage collector as the old buffer is now collectible.\r\n\r\nBoth [Rust](https://github.com/rust-lang/rust/blob/58f32da346642ff3f50186f6f4a0de46e61008be/library/alloc/src/raw_vec.rs#L431) and [Go](https://github.com/golang/go/blob/3f4977bd5800beca059defb5de4dc64cd758cbb9/src/runtime/slice.go#L144-L163) amortize that work by doubling the capacity every time the buffer is exhausted. I’m sure C++ does the same but I couldn’t get through the stdlib code 😅 \r\n\r\nIn an experiment, replacing the `~lib/array/Array` with a `CustomArray\u003cT>` that has exponential buffer growth, the performance problems go away:\r\n\r\n\r\nLanguage | Variant | Runtime | Average | vs JS\r\n-- | -- | -- | -- | --\r\nJavaScript |   |   | 233.68ms | 1.0x\r\nAssemblyScript | customarray | stub | 329.43ms | 1.4x\r\nAssemblyScript | customarray | minimal | 329.23ms | 1.4x\r\nAssemblyScript | customarray | incremental | 335.35ms | 1.4x\r\nAssemblyScript | ~lib | stub | 345.35ms | 1.5x\r\nAssemblyScript | ~lib | minimal | 354.60ms | 1.5x\r\nAssemblyScript | ~lib | incremental | 18758.50ms | 80.3x\r\n\r\nI would like to PR in a fix, but wanted to check first if there are any concerns about adopting a similar approach for ASC’s `Array\u003cT>`?","author":{"url":"https://github.com/surma","@type":"Person","name":"surma"},"datePublished":"2021-04-11T13:13:32Z","url":"https://github.com/AssemblyScript/assemblyscript/issues/1798"}

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:8767f1e7-4832-4fd4-35a4-53b859642406
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD322:1E56FC:631F15:840A91:6B00AA2F
html-safe-nonceb27ce8dad3f333780076c4d1b448331c24b7d600de68f80145e2ae9c2bfa1261
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMzIyOjFFNTZGQzo2MzFGMTU6ODQwQTkxOjZCMDBBQTJGIiwidmlzaXRvcl9pZCI6IjE4ODk4NDQyNTk4MTM2MzI1NTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac8ab7081ce60b497315f06bf769ab4d2a0e819332a90eadba44efbf8c7758c7a3
hovercard-subject-tagissue:855304090
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/AssemblyScript/assemblyscript/1798/issue_layout
twitter:imagehttps://opengraph.githubassets.com/75d927b5168c92466ecff80e800dadd7cac91cb9a1f2e050d0a4adf67742f6be/AssemblyScript/assemblyscript/issues/1798
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/75d927b5168c92466ecff80e800dadd7cac91cb9a1f2e050d0a4adf67742f6be/AssemblyScript/assemblyscript/issues/1798
og:image:altIn a benchmark I discovered that AssemblyScript is significantly slower than JavaScript when using --runtime incremental when filling Arrays. Language Runtime Average vs JS JavaScript 233.68ms 1.0x...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamesurma
hostnamegithub.com
expected-hostnamegithub.com
None455b493e3402a3a3a06beac5d20bb7db3da060808b220aa48d6a7eca7c59863a
turbo-cache-controlno-preview
go-importgithub.com/AssemblyScript/assemblyscript git https://github.com/AssemblyScript/assemblyscript.git
octolytics-dimension-user_id28916798
octolytics-dimension-user_loginAssemblyScript
octolytics-dimension-repository_id105138356
octolytics-dimension-repository_nwoAssemblyScript/assemblyscript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id105138356
octolytics-dimension-repository_network_root_nwoAssemblyScript/assemblyscript
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
release2f575159976167242d488c0b062eb355c4e198b7
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/AssemblyScript/assemblyscript/issues/1798#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FAssemblyScript%2Fassemblyscript%2Fissues%2F1798
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%2FAssemblyScript%2Fassemblyscript%2Fissues%2F1798
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=AssemblyScript%2Fassemblyscript
Reloadhttps://github.com/AssemblyScript/assemblyscript/issues/1798
Reloadhttps://github.com/AssemblyScript/assemblyscript/issues/1798
Reloadhttps://github.com/AssemblyScript/assemblyscript/issues/1798
AssemblyScripthttps://github.com/AssemblyScript
assemblyscripthttps://github.com/AssemblyScript/assemblyscript
Codehttps://github.com/AssemblyScript/assemblyscript
Issues196 (196)https://github.com/AssemblyScript/assemblyscript/issues
Pull requests24 (24)https://github.com/AssemblyScript/assemblyscript/pulls
Actionshttps://github.com/AssemblyScript/assemblyscript/actions
Wikihttps://github.com/AssemblyScript/assemblyscript/wiki
Security and qualityhttps://github.com/AssemblyScript/assemblyscript/security
Insightshttps://github.com/AssemblyScript/assemblyscript/insights
https://github.com/AssemblyScript/assemblyscript
New issuehttps://github.com/login?return_to=https://github.com/AssemblyScript/assemblyscript/issues/1798
New issuehttps://github.com/login?return_to=https://github.com/AssemblyScript/assemblyscript/issues/1798
#1841https://github.com/AssemblyScript/assemblyscript/pull/1841
~lib/array/Array#push is unnecessarily garbage-yhttps://github.com/AssemblyScript/assemblyscript/issues/1798#top
#1841https://github.com/AssemblyScript/assemblyscript/pull/1841
enhancementhttps://github.com/AssemblyScript/assemblyscript/issues?q=state%3Aopen%20label%3A%22enhancement%22
performancehttps://github.com/AssemblyScript/assemblyscript/issues?q=state%3Aopen%20label%3A%22performance%22
https://github.com/surma
surmahttps://github.com/surma
on Apr 11, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issue-855304090
implementationhttps://github.com/AssemblyScript/assemblyscript/blob/42c2dbc987c2e9f4096a226b62bbf0e72b4a0e51/std/assembly/array.ts#L204-L216
Rusthttps://github.com/rust-lang/rust/blob/58f32da346642ff3f50186f6f4a0de46e61008be/library/alloc/src/raw_vec.rs#L431
Gohttps://github.com/golang/go/blob/3f4977bd5800beca059defb5de4dc64cd758cbb9/src/runtime/slice.go#L144-L163
https://github.com/MaxGraey
MaxGraeyhttps://github.com/MaxGraey
on Apr 11, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-817309523
@dcodeIOhttps://github.com/dcodeIO
MaxGraeyhttps://github.com/MaxGraey
enhancementhttps://github.com/AssemblyScript/assemblyscript/issues?q=state%3Aopen%20label%3A%22enhancement%22
performancehttps://github.com/AssemblyScript/assemblyscript/issues?q=state%3Aopen%20label%3A%22performance%22
on Apr 11, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#event-4578556514
https://github.com/dcodeIO
dcodeIOhttps://github.com/dcodeIO
on Apr 11, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-817343265
https://github.com/surma
surmahttps://github.com/surma
on Apr 14, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-819872098
https://github.com/dcodeIO
dcodeIOhttps://github.com/dcodeIO
on Apr 14, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-819875915
https://github.com/MaxGraey
MaxGraeyhttps://github.com/MaxGraey
on Apr 15, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-820247030
https://github.com/AssemblyScript/assemblyscript/blob/master/std/assembly/array.ts#L206https://github.com/AssemblyScript/assemblyscript/blob/master/std/assembly/array.ts#L206
https://github.com/surma
surmahttps://github.com/surma
on Apr 15, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-820289739
https://github.com/carlopi
carlopihttps://github.com/carlopi
on Apr 16, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-821159101
https://github.com/MaxGraey
MaxGraeyhttps://github.com/MaxGraey
on Apr 16, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-821162019
https://github.com/carlopi
carlopihttps://github.com/carlopi
on Apr 16, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-821169371
https://github.com/MaxGraey
MaxGraeyhttps://github.com/MaxGraey
on Apr 16, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-821169537
https://github.com/dcodeIO
dcodeIOhttps://github.com/dcodeIO
on Apr 16, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-821181598
assemblyscript/std/assembly/rt/tlsf.tshttps://github.com/AssemblyScript/assemblyscript/blob/7e20ad2e53c31b3c26591e50de94ed859cda7f7e/std/assembly/rt/tlsf.ts#L5-L9
7e20ad2https://github.com/AssemblyScript/assemblyscript/commit/7e20ad2e53c31b3c26591e50de94ed859cda7f7e
https://github.com/MaxGraey
MaxGraeyhttps://github.com/MaxGraey
on Apr 16, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-821234729
https://github.com/MaxGraey
MaxGraeyhttps://github.com/MaxGraey
on Apr 21, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#issuecomment-824031775
MaxGraeyhttps://github.com/MaxGraey
completedhttps://github.com/AssemblyScript/assemblyscript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#1841https://github.com/AssemblyScript/assemblyscript/pull/1841
on May 3, 2021https://github.com/AssemblyScript/assemblyscript/issues/1798#event-4678363471
Sign up for freehttps://github.com/signup?return_to=https://github.com/AssemblyScript/assemblyscript/issues/1798
Sign in to commenthttps://github.com/login?return_to=https://github.com/AssemblyScript/assemblyscript/issues/1798
enhancementhttps://github.com/AssemblyScript/assemblyscript/issues?q=state%3Aopen%20label%3A%22enhancement%22
performancehttps://github.com/AssemblyScript/assemblyscript/issues?q=state%3Aopen%20label%3A%22performance%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.