Commit Graph

7 Commits

Author SHA1 Message Date
Joe Vilches
c278713eb5 Node -> Measure func map instead of vec (#1581)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1581

This is better than just trusting the order of the measure func call. Now each measure function I/O is associated with a node in the JSON.

Reviewed By: NickGerleman

Differential Revision: D53776790

fbshipit-source-id: 793cf2d9cbf6f663d24848af0af30aa297614eea
2024-02-21 18:02:58 -08:00
Joe Vilches
e2ed3f031d Support for (de)serializing measure funcs
Summary:
In addition to all the state that gets set on the node that is easy to serialize - like floats, enums, bools, etc - we also need to serialize measure functions. This is because these functions take a nontrivial amount of time up during layout and we should capture that. Also, they are important to the ability to truly replay layout as it was captured as the results of the measure functions determine many of the steps the layout algorithm takes.

Capturing this is rather tricky however, but I think I found a solution that is relatively simple and non-error prone. Essentially, since we are capturing the entire tree and virtually every input that goes into the flexbox algorithm, we *should* be able to replay layout exactly as it was captured. This means that the order in which measure functions are called *should* be the same. If this is the case, then all we need to do to capture the measure functions is store their input, output, and duration in a big array. During deserialization we just keep track of an index and use that to determine which measure function we should call. That is the premise behind what happens in this diff. In theory the algorithm could change and the capture would be wrong but it is easy enough to recapture again. Additionally we need to dirty the tree so that we get rid of caching which might omit some measure func calls

In order to capture you need to insert a method exposed by CaptureTree.h into the client measure func, which is kind of annoying but not that bad. In future diffs I will put a macro in place to make this even easier.

I also add our first capture! Which is of a large react native desktop app

Reviewed By: NickGerleman

Differential Revision: D53581121

fbshipit-source-id: 876a230208d67f0ecf76844a4f1b80048353aae2
2024-02-13 17:22:08 -08:00
Joe Vilches
cc66362a28 Expose replacement wrapper of CalculateLayout + (de)serialize layout inputs (#1575)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1575

If we want to replay layouts for benchmark, we should also capture the inputs. This diff does that as well as changing the API in CaptureTree.h. We now expose YGCalculateLayoutWithCapture designed to be a drop-in replacement for YGCalculateLayout. This allows us to have a bit more control on the order of everything and lets us capture measure functions in the next diff much easier.

Reviewed By: NickGerleman

Differential Revision: D53444261

fbshipit-source-id: 616e39153c21e7b472911502b6a717e92c88a4d1
2024-02-09 16:44:32 -08:00
Joe Vilches
753b319977 Support for (de)serializing node state (#1570)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1570

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

tsia. Need node state

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D53206323

fbshipit-source-id: eb48c3873536eb52c8ffcce8005725da274e5373
2024-02-09 16:44:32 -08:00
Joe Vilches
f90ad378ff Support for (de)serializing config values (#1571)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1571

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

tsia. This is state we need to capture as it can drastically affect the benchmark times

Reviewed By: NickGerleman

Differential Revision: D53203385

fbshipit-source-id: 47178458d039df90fb15d8a420f9e0f17e4fe6ca
2024-02-09 16:44:32 -08:00
Joe Vilches
bb83f45872 Change NodeToString.cpp to output JSON not html (#1563)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1563

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

We want to be able to capture Yoga trees in production. To do this we need to serialize and deserialize the in-memory representation of a tree. We have a way to turn a tree into html using NodeToString.cpp but that outputs html, which is going to be hard to deserialize. So, I added the [nlohmann json library](https://github.com/nlohmann/json/tree/develop?tab=readme-ov-file) so that we can serialize into JSON instead. Then we need to change the inner workings of NodeToString.cpp to use this library instead of its html.

One of the bigger structural changes I made was standardizing the checks need to append something to the string. What we want is to only add something if it is not the default style. The existing logic does that but bears the burden of knowing what the default of certain styles actually is. This just calls the getter on a new node to obtain that value, which should simplify things a bit.

Reviewed By: NickGerleman

Differential Revision: D52929268

fbshipit-source-id: 06eff1e10061bcb55fcdeb6f3ebe7e95155b4c86
2024-02-02 15:44:23 -08:00
Joe Vilches
19af9e6450 Move NodeToString.cpp to benchmark and remove interal usages (#1568)
Summary:
X-link: https://github.com/facebook/react-native/pull/42710

Pull Request resolved: https://github.com/facebook/yoga/pull/1568

This is no longer going to be built with normal yoga so we are going to switch to a public API

Reviewed By: NickGerleman

Differential Revision: D53141235

fbshipit-source-id: 259270a4cd91ef0dab91cefba9c41953b6340d78
2024-02-02 15:44:23 -08:00