Add more unit tests for rounding values to pixel grid #1776

Closed
rshest wants to merge 2 commits from export-D67712673 into main

2 Commits

Author SHA1 Message Date
Ruslan Shestopalyuk
76ab9b846a Add more unit tests for rounding values to pixel grid (#1776)
Summary:

# Changelog:
[Internal] - 

I was looking into some profiling results and noticed that Yoga has some quirky custom logic when it comes to rounding to the pixel grid, especially for the values that are halfway through.

There are already unit tests in place, but those cases weren't covered, so I am adding these extra corner cases here, to make sure they are covered in case that the actual rounding function may get modified (which it might make sense to, as it's currently can be more expensive than it could have been in some scenarios).

Differential Revision: D67712673
2024-12-30 02:51:00 -08:00
Ruslan Shestopalyuk
7cb2b9ba55 Avoid calling fmod twice in roundLayoutResultsToPixelGrid (#1775)
Summary:
X-link: https://github.com/facebook/litho/pull/1036


X-link: https://github.com/facebook/react-native/pull/48404

## Changelog:
[Internal] -

This popped up when profiling some heavy UI performance, calling `fmod` operation in Yoga's `roundLayoutResultsToPixelGrid` in `PixelGrid.cpp` can be expensive, furthermore it turns out that some of the calls were redundant.

This replaces the duplicate calls to fmod with an equivalent single round operation, which for e.g. clang compiler on Windows brings the code in question from ~50 instructions (including 4 call instructions to the fmod function) down to ~30 instructions (without any external calls), and the layout operation being **~1% more efficient** for the particular benchmark I was looking into.

Differential Revision: D67689065
2024-12-30 02:51:00 -08:00