René's URL Explorer Experiment


Title: perf(runtime): drop per-call struct, size and swizzle lookups around ffi_call by edusperoni · Pull Request #511 · NativeScript/ios · GitHub

Open Graph Title: perf(runtime): drop per-call struct, size and swizzle lookups around ffi_call by edusperoni · Pull Request #511 · NativeScript/ios

X Title: perf(runtime): drop per-call struct, size and swizzle lookups around ffi_call by edusperoni · Pull Request #511 · NativeScript/ios

Description: Motivation ffi_call itself is a small part of a native call from JS (~12-18 ns with a cached cif, measured in #496/#366). Reading the call paths around it showed per-call work whose answer never changes for a given method or type: every by-value struct argument, return and nested field resolved its StructInfo from scratch: a std::string built from the declaration name, ArgConverter::GetMeta taking a std::mutex and hashing it, then FFICall::GetStructInfo copying the name again, taking a spinlock and hashing it a second time. Anonymous structs rebuilt their cache key through a std::stringstream on every call. several sites built an ffi_type (heap-allocating for constant arrays and vectors) only to read its size and dispose it again: null/undefined arguments, by-reference out parameters, constant-array arguments, fields and returns. every instance method call looked up __NativeScript__ under a spinlock and sent respondsToSelector: for it, although only selectors the runtime swizzled (assigning to a native class's prototype) can ever have that twin. methods with an omitted NSError** calloc/freed a pointer-sized slot per call; closure callbacks heap-allocated a std::vector for their JS arguments. Changes FFICall::GetStructInfo(const TypeEncoding*): resolves a StructDeclarationReference or AnonymousStructEncoding once and caches the StructInfo* by encoding address. Metadata encodings live for the process; the runtime-built ones (Interop::CreateEncoding, ClassBuilder's exposed methods) are never freed and never describe structs, the same assumption the existing cif cache (ParametrizedCall, keyed by TypeEncoding*) makes. It resolves exactly as GetResult and the cif's ffi_type already did (meta looked up by the encoding's jsName), so struct objects keep the same StructInfo identity and per-type template as before. FFICall::GetTypeSize(encoding, isStructMember): the size GetArgumentType(...)->size reports, without building or disposing anything. Replaces every build-read-dispose pair. Interop::RegisterSwizzledSelector is called by the three swizzle sites in MetadataBuilder before class_replaceMethod; GetSwizzledMethodSelector returns nullptr for any selector never registered, and returns without taking the lock while nothing has been swizzled at all (process-wide atomic flag). The respondsToSelector: probe still runs, per receiver, for registered selectors, so a swizzle on a superclass, an NSKVONotifying_* subclass or a class created later is still seen. Third-party swizzling (method_exchangeImplementations) never produced a __NativeScript__ twin, and is still honoured because the call goes through objc_msgSend. The NSError** slot is a zero-initialized stack variable. ArgConverter::MethodCallback collects up to 8 JS arguments in an inline array (heap fallback above that). Measurements Release TestRunner, iPhone 16 Pro simulator (iOS 26.2) on an M4 Pro. Both builds come from the same worktree (main = NativeScript/runtime at 20935bd), and only the bench specs were run, with no test suite before them. Each run takes the best of 5 × 100k per case; the table shows the median of 5 runs per build, alternating main/branch. Run-to-run noise is about 3%. Specs that don't touch changed code (class methods, C functions, JS controls) moved ±3%. case main branch delta struct return: view.frame 274 232 -16% screen.bounds 279 229 -18% screen.bounds.size.width 515 428 -17% UIScreen.mainScreen.bounds.size.width 656 574 -12% struct arg (plain object): view.frame = {...} 717 550 -23% struct arg (plain object): NSValue.valueWithCGRect({...}) 1498 1263 -16% struct arg (struct object): view.frame = rect 205 198 -3% struct arg (null): NSValue.valueWithCGRect(null) 990 934 -6% anonymous struct round trip (TNSTestNativeCallbacks.recordsNestedAnonymousStruct) 1649 1281 -22% NSError out-param omitted: api.methodError(0) 559 536 -4% block callback, per item: enumerateObjectsUsingBlock(noop) 466 423 -9% arr.count 86 83 -3% arr.indexOfObject(obj) 122 118 -4% obj.isKindOfClass(NSObject) 196 190 -3% view.setNeedsLayout() 110 106 -4% screen.nativeScale 146 142 -3% Plain instance calls gain only a few ns from skipping respondsToSelector:, since that probe hits the method cache. The fixture-based cases include the fixture's own TNSLog/stringWithFormat: work, so their absolute numbers overstate the runtime's share. The bench specs and harness (Release build, a minimal runner replacing app/index.js, results read from the app container) live outside the tree, in bench/ of the main checkout, like the ones for #496. Testing ./run_tests.sh (Debug, dedicated simulator): 1835 specs, 0 failures, 11 skipped. ASan run: ./run_tests.sh -a (AddressSanitizer): 1835 specs, 0 failures, 16 skipped, no ASan reports. Follow-ups not in this PR (riskier, or need more analysis) Is the receiver's class JS-extended (ArgConverter::Invoke): every instance call hashes object_getClassName(target) into ClassPrototypes and copies the Caches shared_ptr (atomic inc/dec). Caching this per Class pointer looks right, because a class is extended at creation. But ClassPrototypes is per isolate, and how HMR re-extension names and replaces classes needs checking first. Hoisting the cif and selector lookups into CacheItem: ParametrizedCall::Get and MethodMeta::selector() are a spinlocked hash lookup each, on every call. Hoisting them needs plumbing through ObjCMethodCall/Invoke; #496 estimated this at ~5%. Lock-free swizzle check after the first swizzle: once any selector is swizzled, every instance call takes the registry spinlock again, as on main. A per-selector generation stamp cached at the call site would make this lock-free. That only matters for apps that patch native prototypes. Vector (simd) returns still allocate an ffi_type per return (Interop::GetResult, ExtVector branch). The wrapper owns it, and ObjectManager disposes it. Sharing one per encoding means changing that ownership, so it's left alone here. Struct identity for renamed structs: the global constructor (MetadataBuilder struct branch) keys StructInfo by the native name, while returns and the cif key it by jsName. For a struct whose jsName differs, the two get distinct StructInfos, and so distinct prototypes and instanceof results. This predates this PR, which keeps the jsName side. Unifying the two is a behavior change. Closure callback lifetimes: MethodCallback still copies the callback's shared_ptr and the Caches shared_ptr per invocation. Dropping those copies needs a lifetime argument: the wrapper or block can be disposed while the JS callback runs. Class returns (GetResult, ClassEncoding) call GetMeta and ObjectCtorInitializer per return. That path wasn't measured here. cifs keyed by encoding address, not by signature: identical signatures never share a cif. This costs memory and first-call time only, not throughput. Replacing ffi_call itself with direct objc_msgSend stubs is #366.

Open Graph Description: Motivation ffi_call itself is a small part of a native call from JS (~12-18 ns with a cached cif, measured in #496/#366). Reading the call paths around it showed per-call work whose answer never ch...

X Description: Motivation ffi_call itself is a small part of a native call from JS (~12-18 ns with a cached cif, measured in #496/#366). Reading the call paths around it showed per-call work whose answer never ch...

Opengraph URL: https://github.com/NativeScript/ios/pull/511

X: @github

direct link

Domain: github.com

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:13bc943c-bd9a-8d05-753e-fb352edb721a
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE2EA:2E7A8:1CC66:2583D:6B017F68
html-safe-noncec8958de52879c65d1292d0b43fcf75c8ae5fe47d8b4b33a4b98d84eea350f1b9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkVBOjJFN0E4OjFDQzY2OjI1ODNEOjZCMDE3RjY4IiwidmlzaXRvcl9pZCI6IjY3NjMzNTc1NzkxNjM4MjgwNzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac9a5a45cedc31350c08f9cea73d54dda1681202a7fc9a2d29688de0823a99b09c
hovercard-subject-tagpull_request:4847138244
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/NativeScript/ios/pull/511/files
twitter:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
og:image:altMotivation ffi_call itself is a small part of a native call from JS (~12-18 ns with a cached cif, measured in #496/#366). Reading the call paths around it showed per-call work whose answer never ch...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/NativeScript/ios git https://github.com/NativeScript/ios.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id172934359
octolytics-dimension-repository_nwoNativeScript/ios
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id172934359
octolytics-dimension-repository_network_root_nwoNativeScript/ios
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/NativeScript/ios/pull/511/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fios%2Fpull%2F511%2Ffiles
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%2FNativeScript%2Fios%2Fpull%2F511%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=NativeScript%2Fios
Reloadhttps://github.com/NativeScript/ios/pull/511/files
Reloadhttps://github.com/NativeScript/ios/pull/511/files
Reloadhttps://github.com/NativeScript/ios/pull/511/files
NativeScripthttps://github.com/NativeScript
ioshttps://github.com/NativeScript/ios
Codehttps://github.com/NativeScript/ios
Issues56 (56)https://github.com/NativeScript/ios/issues
Pull requests42 (42)https://github.com/NativeScript/ios/pulls
Actionshttps://github.com/NativeScript/ios/actions
Projectshttps://github.com/NativeScript/ios/projects
Security and qualityhttps://github.com/NativeScript/ios/security
Insightshttps://github.com/NativeScript/ios/insights
Sign up for GitHub https://github.com/signup?return_to=%2FNativeScript%2Fios%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FNativeScript%2Fios%2Fissues%2Fnew%2Fchoose
edusperonihttps://github.com/edusperoni
mainhttps://github.com/NativeScript/ios/tree/main
perf/ffi-call-overheadhttps://github.com/NativeScript/ios/tree/perf/ffi-call-overhead
Conversation 1 https://github.com/NativeScript/ios/pull/511
Commits 1 https://github.com/NativeScript/ios/pull/511/commits
Checks 9 https://github.com/NativeScript/ios/pull/511/checks
Files changed https://github.com/NativeScript/ios/pull/511/files
Please reload this pagehttps://github.com/NativeScript/ios/pull/511/files
perf(runtime): drop per-call struct, size and swizzle lookups around ffi_call https://github.com/NativeScript/ios/pull/511/files#top
Show all changes 1 commit https://github.com/NativeScript/ios/pull/511/files
c245bc8 perf(runtime): drop per-call struct, size and swizzle lookups around … edusperoni Oct 13, 2026 https://github.com/NativeScript/ios/pull/511/commits/c245bc8a4da656531930faedece9c5a29a4e99e1
Clear filters https://github.com/NativeScript/ios/pull/511/files
Please reload this pagehttps://github.com/NativeScript/ios/pull/511/files
Please reload this pagehttps://github.com/NativeScript/ios/pull/511/files
ArgConverter.mm https://github.com/NativeScript/ios/pull/511/files#diff-65a98e0ce763ac29ef9ed8dd75b8b8d92447c04ffc1bfb5df78f5d33b67e2091
FFICall.cpp https://github.com/NativeScript/ios/pull/511/files#diff-5fe41ad6a1ddacf290fe7a38e94640fddb3801b58dafdccd433fbdc5286bb995
FFICall.h https://github.com/NativeScript/ios/pull/511/files#diff-7cd8c855a0e9ac9477d4150f72af17170a1e258f7941269ba9df622dacfcc25f
Interop.h https://github.com/NativeScript/ios/pull/511/files#diff-67e1f294f22c66589e9270b894949f54adbc8ff8230ba8b499830ee305723d59
Interop.mm https://github.com/NativeScript/ios/pull/511/files#diff-bec6e3d6b4fa0eacfb7726d6e5915c9eecda4e319bc61f71a0527e740eb197dd
MetadataBuilder.mm https://github.com/NativeScript/ios/pull/511/files#diff-53444a9d5f4483b94a9b889fdf4f44e9d6b06b733fd0ef0761c13d887e331e65
Reference.cpp https://github.com/NativeScript/ios/pull/511/files#diff-3082d2f4ab6f63b8c104be9f48aabcfefeeff2b4153cfc4ff403927fb6ec2c59
NativeScript/runtime/ArgConverter.mmhttps://github.com/NativeScript/ios/pull/511/files#diff-65a98e0ce763ac29ef9ed8dd75b8b8d92447c04ffc1bfb5df78f5d33b67e2091
View file https://github.com/NativeScript/ios/blob/c245bc8a4da656531930faedece9c5a29a4e99e1/NativeScript/runtime/ArgConverter.mm
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/ios/pull/511/{{ revealButtonHref }}
https://github.com/NativeScript/ios/pull/511/files#diff-65a98e0ce763ac29ef9ed8dd75b8b8d92447c04ffc1bfb5df78f5d33b67e2091
https://github.com/NativeScript/ios/pull/511/files#diff-65a98e0ce763ac29ef9ed8dd75b8b8d92447c04ffc1bfb5df78f5d33b67e2091
https://github.com/NativeScript/ios/pull/511/files#diff-65a98e0ce763ac29ef9ed8dd75b8b8d92447c04ffc1bfb5df78f5d33b67e2091
https://github.com/NativeScript/ios/pull/511/files#diff-65a98e0ce763ac29ef9ed8dd75b8b8d92447c04ffc1bfb5df78f5d33b67e2091
https://github.com/NativeScript/ios/pull/511/files#diff-65a98e0ce763ac29ef9ed8dd75b8b8d92447c04ffc1bfb5df78f5d33b67e2091
https://github.com/NativeScript/ios/pull/511/files#diff-65a98e0ce763ac29ef9ed8dd75b8b8d92447c04ffc1bfb5df78f5d33b67e2091
https://github.com/NativeScript/ios/pull/511/files#diff-65a98e0ce763ac29ef9ed8dd75b8b8d92447c04ffc1bfb5df78f5d33b67e2091
NativeScript/runtime/FFICall.cpphttps://github.com/NativeScript/ios/pull/511/files#diff-5fe41ad6a1ddacf290fe7a38e94640fddb3801b58dafdccd433fbdc5286bb995
View file https://github.com/NativeScript/ios/blob/c245bc8a4da656531930faedece9c5a29a4e99e1/NativeScript/runtime/FFICall.cpp
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/ios/pull/511/{{ revealButtonHref }}
https://github.com/NativeScript/ios/pull/511/files#diff-5fe41ad6a1ddacf290fe7a38e94640fddb3801b58dafdccd433fbdc5286bb995
https://github.com/NativeScript/ios/pull/511/files#diff-5fe41ad6a1ddacf290fe7a38e94640fddb3801b58dafdccd433fbdc5286bb995
https://github.com/NativeScript/ios/pull/511/files#diff-5fe41ad6a1ddacf290fe7a38e94640fddb3801b58dafdccd433fbdc5286bb995
https://github.com/NativeScript/ios/pull/511/files#diff-5fe41ad6a1ddacf290fe7a38e94640fddb3801b58dafdccd433fbdc5286bb995
https://github.com/NativeScript/ios/pull/511/files#diff-5fe41ad6a1ddacf290fe7a38e94640fddb3801b58dafdccd433fbdc5286bb995
https://github.com/NativeScript/ios/pull/511/files#diff-5fe41ad6a1ddacf290fe7a38e94640fddb3801b58dafdccd433fbdc5286bb995
NativeScript/runtime/FFICall.hhttps://github.com/NativeScript/ios/pull/511/files#diff-7cd8c855a0e9ac9477d4150f72af17170a1e258f7941269ba9df622dacfcc25f
View file https://github.com/NativeScript/ios/blob/c245bc8a4da656531930faedece9c5a29a4e99e1/NativeScript/runtime/FFICall.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/ios/pull/511/{{ revealButtonHref }}
https://github.com/NativeScript/ios/pull/511/files#diff-7cd8c855a0e9ac9477d4150f72af17170a1e258f7941269ba9df622dacfcc25f
https://github.com/NativeScript/ios/pull/511/files#diff-7cd8c855a0e9ac9477d4150f72af17170a1e258f7941269ba9df622dacfcc25f
https://github.com/NativeScript/ios/pull/511/files#diff-7cd8c855a0e9ac9477d4150f72af17170a1e258f7941269ba9df622dacfcc25f
NativeScript/runtime/Interop.hhttps://github.com/NativeScript/ios/pull/511/files#diff-67e1f294f22c66589e9270b894949f54adbc8ff8230ba8b499830ee305723d59
View file https://github.com/NativeScript/ios/blob/c245bc8a4da656531930faedece9c5a29a4e99e1/NativeScript/runtime/Interop.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/ios/pull/511/{{ revealButtonHref }}
https://github.com/NativeScript/ios/pull/511/files#diff-67e1f294f22c66589e9270b894949f54adbc8ff8230ba8b499830ee305723d59
https://github.com/NativeScript/ios/pull/511/files#diff-67e1f294f22c66589e9270b894949f54adbc8ff8230ba8b499830ee305723d59
https://github.com/NativeScript/ios/pull/511/files#diff-67e1f294f22c66589e9270b894949f54adbc8ff8230ba8b499830ee305723d59
https://github.com/NativeScript/ios/pull/511/files#diff-67e1f294f22c66589e9270b894949f54adbc8ff8230ba8b499830ee305723d59
Please reload this pagehttps://github.com/NativeScript/ios/pull/511/files
Please reload this pagehttps://github.com/NativeScript/ios/pull/511/files
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.