Ability to recreate yoga trees from JSON captures #1566

Closed
joevilches wants to merge 3 commits from export-D52987588 into main

3 Commits

Author SHA1 Message Date
Joe Vilches
a1b1d5d05e Ability to recreate yoga trees from JSON captures
Summary:
In the previous diffs we serialized the in-memory representation of a node into json. This diff exposes a `generateBenchmark` method that reads from that json executes the proper public Yoga API functions to recreate the same tree. It then calls calculate layout so that we can time that in the next diff.

This diff is really only focusing on the core aspects of a yoga tree like style, children, and calculating layout; there are still more things to add coming up:

* Support for configs, experiments, and errata
* Support for measure functions
* Support for general node state that is not style (like always forming a containing block)
* Actually running all of these benchmarks together
* Tests

Differential Revision: D52987588
2024-01-24 12:30:22 -08:00
Joe Vilches
568671266e Ability to capture trees as JSON files (#1565)
Summary:

This adds a `captureTree` method intended to be injected in somewhere where you would like a JSON representation of a yoga tree (like in calculateLayout). Right now it is very simple and just calls on `nodeToString` to serialize a node into JSON, and then saves that into a file in the `benchmark` dir. Some buck file changes needed to be done as well as this is the first `.cpp` file in `benchmark`

Differential Revision: D52972995
2024-01-24 12:30:22 -08:00
Joe Vilches
295741c1b4 Change NodeToString.cpp to output JSON not html
Summary:
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.

Differential Revision: D52929268
2024-01-24 12:30:22 -08:00