Ability to recreate yoga trees from JSON captures (#1566)

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

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

Reviewed By: NickGerleman

Differential Revision: D52987588

fbshipit-source-id: 7f7c9ca9956f693be62bc5e3cebdf1aed6f58aec
This commit is contained in:
Joe Vilches
2024-02-05 11:48:07 -08:00
committed by Facebook GitHub Bot
parent efd27efd70
commit 0ca15bdaaa
5 changed files with 366 additions and 6 deletions

View File

@@ -29,9 +29,9 @@ static void appendYGValueIfNotDefault(
const YGValue& defaultValue) {
if (value != defaultValue) {
if (value.unit == YGUnitAuto) {
j["style"][key]["unit"] = "auto";
j["style"][key] = "auto";
} else if (value.unit == YGUnitUndefined) {
j["style"][key]["unit"] = "undefined";
j["style"][key] = "undefined";
} else {
std::string unit = value.unit == YGUnitPoint ? "px" : "%%";
j["style"][key]["value"] = value.value;