Skip to content

Optimize style value resolution with handle-based approach#1922

Open
paradowstack wants to merge 1 commit intofacebook:mainfrom
paradowstack:feat/style-optimize
Open

Optimize style value resolution with handle-based approach#1922
paradowstack wants to merge 1 commit intofacebook:mainfrom
paradowstack:feat/style-optimize

Conversation

@paradowstack
Copy link
Copy Markdown

@paradowstack paradowstack commented Mar 26, 2026

Summary:

This PR is an optimization attempt during work on the calc() feature: #1874.
It aims to reduce the regression effect on layout operations after extending the size of StyleLength and StyleSizeLength classes.

Changelog:

This PR introduces a private resolve(StyleValueHandle handle, float referenceLength) function to Style.h that resolves its property values directly from StyleValueHandle and skips creating intermediate objects.

I am aware that this duplicates the resolving functionality that already exists in StyleLength.h and StyleSizeLength.h, and may not be the cleanest solution. Optimization could go even further and totally drop the resolve() function from StyleLength.h and StyleSizeLength.h, and replace all usages with the newly introduced functions. But I think the performance boost is not high enough to justify that. Also it won't be the best API for Yoga library consumers - that's why I decided to keep them. However, I am opening this PR to start a discussion and would really like to hear opinions about it.

Benchmarks:

Results were averaged over 20 runs.

This does not bring much gain in terms of performance when compared to the main branch.
image

However, it introduces a significant boost for the calc() and YGValueDynamic work.

Results before these optimizations:
image

And after:
image

cc @NickGerleman

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
yoga-website Ready Ready Preview, Comment Mar 26, 2026 5:30pm

Request Review

@meta-cla meta-cla bot added the CLA Signed label Mar 26, 2026
@paradowstack paradowstack marked this pull request as ready for review March 26, 2026 18:09
@facebook-github-tools facebook-github-tools bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Mar 26, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Mar 31, 2026

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this in D99006553.

NickGerleman pushed a commit to NickGerleman/react-native that referenced this pull request Apr 1, 2026
Summary:
This PR is an optimization attempt during work on the `calc()` feature: facebook/yoga#1874.
It aims to reduce the regression effect on layout operations after extending the size of `StyleLength` and `StyleSizeLength` classes.

## Changelog:
This PR introduces a private `resolve(StyleValueHandle handle, float referenceLength)` function to `Style.h` that resolves its property values directly from `StyleValueHandle` and skips creating intermediate objects.

I am aware that this duplicates the resolving functionality that already exists in `StyleLength.h` and `StyleSizeLength.h`, and may not be the cleanest solution. Optimization could go even further and totally drop the `resolve()` function from `StyleLength.h` and `StyleSizeLength.h`, and replace all usages with the newly introduced functions. But I think the performance boost is not high enough to justify that. Also it won't be the best API for Yoga library consumers - that's why I decided to keep them. However, I am opening this PR to start a discussion and would really like to hear opinions about it.

## Benchmarks:
Results were averaged over 20 runs.

This does not bring much gain in terms of performance when compared to the main branch.
<img width="1366" height="254" alt="image" src="https://github.com/user-attachments/assets/19ec2a31-db60-46bc-84e1-5ad8eb9ddfcd" />

However, it introduces a significant boost for the calc() and YGValueDynamic work.

Results before these optimizations:
<img width="1390" height="276" alt="image" src="https://github.com/user-attachments/assets/68c17e88-78e2-439b-bf09-acb869d5533d" />

And after:
<img width="1363" height="252" alt="image" src="https://github.com/user-attachments/assets/212b9d11-5e02-4524-b9ba-90b43130d02c" />

cc NickGerleman

X-link: facebook/yoga#1922

Reviewed By: zeyap

Differential Revision: D99006553

Pulled By: NickGerleman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

1 participant