Skip to content

Optimize style value resolution with handle-based approach#56306

Open
NickGerleman wants to merge 1 commit intofacebook:mainfrom
NickGerleman:export-D99006553
Open

Optimize style value resolution with handle-based approach#56306
NickGerleman wants to merge 1 commit intofacebook:mainfrom
NickGerleman:export-D99006553

Conversation

@NickGerleman
Copy link
Copy Markdown
Contributor

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.
image

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

Results before these optimizations:
image

And after:
image

cc NickGerleman

X-link: facebook/yoga#1922

Reviewed By: zeyap

Differential Revision: D99006553

Pulled By: NickGerleman

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
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 1, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync bot commented Apr 1, 2026

@NickGerleman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D99006553.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants