GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(ios): lay out views with fewer native calls by triniwiz · Pull Request #11544 · NativeScript/NativeScript

Conversation

@triniwiz

@triniwiz triniwiz commented Oct 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

PR Checklist

  • The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages.
  • There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it.
  • You have signed the CLA.
  • All existing tests are passing: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/DevelopmentWorkflow.md#running-unit-tests-application.
  • Tests for the changes are included - https://github.com/NativeScript/NativeScript/blob/master/tools/notes/WritingUnitTests.md.

What is the current behavior?

Laying out a tree on iOS spends most of its time marshalling between JS and UIKit rather than in UIKit. Containers (layouts, ScrollView, Page content) default to iosOverflowSafeArea, so every time a container's frame changes, IOSHelper.expandBeyondSafeArea builds four CGRects (the safe area, the full area, the frame in the window, the frame) and reads each one back through getPositionFromFrame: about 70 native getter and struct calls per view, for a result that is the frame itself unless the view touches the edge of the safe area.

Instrumenting core's layout methods in the xplat-benchmarks ns-core app (iOS simulator, a 1,093-view tree) showed each resize calling getPositionFromFrame about 5 times per view, and applySafeAreaInsets taking more time than all the measuring.

What is the new behavior?

The results are the same; the native calls are fewer.

  • expandBeyondSafeArea reads each native value once (the reference scroll view's insets, content size and offset, or the controller's safe-area guide and frame; the view's location in the window; the frame) and computes the positions in JS with the same arithmetic. When nothing is expanded and the frame is already on device pixels, it returns the frame itself, and _modifyNativeViewFrame doesn't set it a second time. getAvailableSpaceFromParent is unchanged for other callers.
  • layout() uses the position of a frame it has just set, unadjusted and untransformed, instead of reading the native frame back. A transformed view's frame is still read, since it is its transformed bounding box.
  • layoutNativeView() skips the native calls when the position is the one it last laid out, which _setNativeViewFrame would leave alone anyway.
  • getSafeAreaInsets() checks iosIgnoreSafeArea and the managed-inset ancestor before reading the native insets.
  • layout.measureNativeView() and Label's text measure return plain objects instead of writing into the CGSize, which goes through native struct setters.

Performance

xplat-benchmarks ns-core app (plain core layouts, no plugins), iPhone 17 Pro Max simulator (iOS 26.4), size M, 3 interleaved rounds of 10 iterations, median ms until painted. To reproduce, point apps/ns-core at each build of core, build it with scripts/build-ios.sh <simulator-udid> ns-core, and run npm run bench -- run --platform ios --device <udid> --apps ns-core --scenarios mount,relayout --sizes M --rounds 3 (see the repo's README):

Case main this PR main / PR
relayout-resize grow 144.2 80.0 1.80
relayout-resize shrink 116.1 64.2 1.81
relayout-style restyle 171.7 102.9 1.67
relayout-style restore 141.3 90.6 1.56
insert-remove remove 277.4 178.3 1.56
insert-remove insert 364.1 281.4 1.29
tree-fanout mount 248.9 181.2 1.37
grid-dashboard mount 217.9 190.2 1.15
styled-cards mount 289.8 260.5 1.11
flex-wrap-tiles mount 817.5 742.8 1.10
nested-chain mount 24.5 22.8 1.07
text-flow mount 158.0 153.4 1.03

Tests

  • view-helper/safe-area-expansion.spec.ts runs the new expandBeyondSafeArea and the previous computation (getAvailableSpaceFromParent + getPositionFromFrame) on 2,000 generated frames inside a scroll view and a view controller, with notched insets and fractional positions, and requires identical rects (over 200 of them expanded).
  • view-helper/frame-position.spec.ts checks the JS position against reading it back from the frame.
  • apps/automated passes on the iOS 26.4 simulator (1827 OK, 0 failed), including the 137 SAFEAREA layout, list view, scroll view, repeater and web view tests. The source changes are iOS-only (.ios.ts files, plus two declarations in view-helper/index.d.ts).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@triniwiz
perf(ios): lay out views with fewer native calls
9fa576c
Laying out a tree on iOS spent most of its time marshalling between JS
and UIKit rather than in UIKit itself. Containers (layouts, ScrollView,
Page content) default to iosOverflowSafeArea, so every time a container's
frame changed, expandBeyondSafeArea built four CGRects (the safe area,
the full area, the frame in the window, the frame) and read each one back
through getPositionFromFrame: about 70 native getter calls per view, for
a result that is the frame itself unless the view touches the edge of the
safe area.

- expandBeyondSafeArea reads each native value once (the reference's
  insets, content size and offset or safe-area guide, the view's location
  in the window, the frame) and computes the positions in JS with the same
  arithmetic, so the result is identical. When nothing is expanded and the
  frame is already on device pixels, it returns the frame itself, and the
  frame is not set a second time.
- layout() uses the position of a frame it has just set, unadjusted and
  untransformed, instead of reading the native frame back.
- layoutNativeView() skips the native calls when the position is the one
  it last laid out, which _setNativeViewFrame would leave alone anyway.
- getSafeAreaInsets() checks iosIgnoreSafeArea and the managed-inset
  ancestor before reading the native insets.
- measureNativeView() and Label's text measure return plain objects
  instead of writing into the CGSize, which goes through native struct
  setters.

On the xplat-benchmarks ns-core app (iPhone 17 Pro Max simulator, size M,
3 interleaved rounds), resizing a 1,093-view tree went from 148 ms to
81 ms (grow) and 118 ms to 65 ms (shrink), restyling it from 174 ms to
103 ms, and mounting it from 250 ms to 181 ms.
@nx-cloud

nx-cloud Bot commented Oct 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit b24f3e8

Command Status Duration Result
nx run-many -t build -p core,webpack5,vite ✅ Succeeded 2s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-10-15 20:36:08 UTC

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11544
npm i https://pkg.pr.new/@nativescript/vite@11544
npm i https://pkg.pr.new/@nativescript/webpack@11544

commit: b24f3e8

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

farfromrefug
farfromrefug reviewed Oct 15, 2026
View reviewed changes
Comment thread packages/core/ui/core/view/index.ios.ts
right,
bottom,
});
this._pendingFramePosition = IOSHelper.getPositionFromFramePosition(left, top, right, bottom);

@farfromrefug farfromrefug Oct 15, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isnt it a duplicate cost as you already go through parents in getFrameFromPosition? Cant we get position from frame?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/ui/core/view/index.ios.ts Outdated
// get the frame and adjust the position, so that onLayout works correctly
position = IOSHelper.getPositionFromFrame(this.nativeViewProtected.frame);
// get the frame and adjust the position, so that onLayout works correctly.
// A frame set here without adjustment is known without reading it back

@farfromrefug farfromrefug Oct 15, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those AI comments are too long. In the end it will pollute the code. We should keep them small

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/ui/core/view/index.ios.ts
if (IOSHelper.hasIOSManagedInsetAncestor(this)) {
return insets;
}
const safeAreaInsets = this.nativeViewProtected && this.nativeViewProtected.safeAreaInsets;

@farfromrefug farfromrefug Oct 15, 2026

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const safeAreaInsets = this.nativeViewProtected?.safeAreaInsets

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@edusperoni

edusperoni commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

A few of these optimizations might not be needed anymore since accessing structs is now a few ns. Some paths had 20x speedup so what you're doing might even have become suboptimal now under jitless

NativeScript/ios#499

triniwiz reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@triniwiz

triniwiz commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

@edusperoni nice I'll rerun the benchmarks to see new numbers.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@triniwiz
chore(ios): drop comments
b24f3e8

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@farfromrefug farfromrefug farfromrefug left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@triniwiz @edusperoni @farfromrefug
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.