51 Commits

Author SHA1 Message Date
Joe Vilches
194f83dea5 Add mobile yoga tree captures (#1640)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1640

Added two captures that were captured from a mobile device.

**profile-ios**: A profile-like view with a central picture and some text information underneath. Captured on iOS device
**feed-android** A feed-like view with a scrollable list of images and text. Captured on Android device.

Fixed a bug that would not deserialize undefined values

Reviewed By: NickGerleman

Differential Revision: D55712235

fbshipit-source-id: ed32b393c088c695d8191149c729e51008df4e7e
2024-04-05 14:01:54 -07:00
Bruce Mitchener
9dcd8ba9dc Fix typos. (#1629)
Summary:
This fixes a variety of spelling mistakes in file names, identifiers, and comments.

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

Reviewed By: NickGerleman

Differential Revision: D54987359

Pulled By: yungsters

fbshipit-source-id: 6b7ca20f4855f5f654036672bc10f8b079288acd
2024-03-19 02:52:40 -07:00
Nick Gerleman
b959c79a2a Enable Clang Tidy (#1586)
Summary:
X-link: https://github.com/facebook/litho/pull/976

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

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

Add the React Clang Tidy config to Yoga, run the auto fixes, and make some manual mechanical tweaks.

Notably, the automatic changes to the infra for generating a Yoga tree from JSON capture make it 70% faster.

Before:
{F1463947076}

After:
{F1463946802}

This also cleans up all the no-op shallow const parameters in headers.

{F1463943386}

Not all checks are available in all environments, but that is okay, as Clang Tidy will gracefully skip them.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D54461054

fbshipit-source-id: dbd2d9ce51afd3174d1f2c6d439fa7d08baff46f
2024-03-04 02:28:02 -08:00
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
b35456b93c Error message when measure functions mismatch
Summary:
To sanity check that a capture is working as expected when running benchmark

We could maybe even throw here as a bad measure function will throw off the rest of the benchmark.

Reviewed By: NickGerleman

Differential Revision: D53681506

fbshipit-source-id: f5ab7e00e76df0ac899d62c3f6b4535b3780d45d
2024-02-13 17:22:08 -08:00
Joe Vilches
e679327904 Add small desktop capture
Summary: A much smaller tree than the previous one. It only has 100 or so nodes

Reviewed By: NickGerleman

Differential Revision: D53632451

fbshipit-source-id: 1268499fa768f3b6673ff8bcedac23cf6d9395ac
2024-02-13 17:22:08 -08:00
Joe Vilches
cae7ef924a Convience script to run benchmark
Summary: You need to provide the benchmark binary with a path to the captures. This is annoying and there is not a great way to do this in c++ that is cross-plat. So I just made this bash script to ease it. It can do buck and cmake.

Reviewed By: NickGerleman

Differential Revision: D53632438

fbshipit-source-id: 98b0ad52f91f2581e09f787da24f2ec2fff58bf4
2024-02-13 17:22:08 -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
a37565f70d Fix failing MVSC benchmark builds (#1573)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1573

Noticed a recent stack of commits cause the MVSC builds of benchmark to fail. This was due to forgetting to call `.string()` of a path and trying to escape a character that cannot be escaped.

Reviewed By: philIip

Differential Revision: D53461723

fbshipit-source-id: b6cc034d53b3a61929012965e257a3984c3bff47
2024-02-06 11:16:21 -08:00
Joe Vilches
94960f123e main() function to run a benchmark (#1564)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1564

tsia

Reviewed By: NickGerleman

Differential Revision: D53028962

fbshipit-source-id: dee2670eaa4fe0ab8b6e2b9e1bbe4356bb2c0735
2024-02-05 11:48:07 -08:00
Joe Vilches
8dbf55f230 Add ability to time captured benchmarks (#1569)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1569

Added a `benchmark` function that takes a path representing a directory to read captures from. This is supplied by the caller due to annoyance with filesystem access in C++. This calls into timing code with <chrono> and prints it out to the console.

Reviewed By: NickGerleman

Differential Revision: D53104632

fbshipit-source-id: fe8bcb0a87198701865fb04193894591d2eff821
2024-02-05 11:48:07 -08:00
Joe Vilches
0ca15bdaaa 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
2024-02-05 11:48:07 -08:00
Nick Gerleman
f9c2c27d33 Use fbsource clang-format config
Summary:
This mirrors the clang-format config used by fbsource to Yoga.

They are pretty similar, except for an annoying habit where Yoga's previous forced small functions in headers to be a a single line, so you would get a combination of multiline and single line functions next to each other which are hard to read. That is what motivated this change.

It also enforces header ordering (yay). I don't think we have any side-effect causing headers, so this should be safe.

Reviewed By: yungsters

Differential Revision: D49248994

fbshipit-source-id: 66998395e7c0158ff9d9fb1bee44e8401bdd8f21
2023-09-13 20:12:55 -07:00
Nick Gerleman
26f2b28eca Breaking: Fix callback const-correctness (#1369)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1369

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

This fixes const-correctness of callbacks (e.g. not letting a logger function modify nodes during layout). This helps us to continue to fix const-correctness issues inside of Yoga.

This change is breaking to the public API, since it requires a change in signature passed to Yoga.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49130714

fbshipit-source-id: 4305f8882d89f296e45b78497a51716a0dbb3b2d
2023-09-11 19:51:40 -07:00
Nick Gerleman
aee43a53bc Enable -Wconversion (#1359)
Summary:
X-link: https://github.com/facebook/react-native/pull/39291

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

This enables clang warnings around potentially unsafe conversions, such as those with mismatched signedness, or ones which may lead to truncation.

This should catch issues in local development which create errors for MSVC (e.g. Dash), who's default `/W3` includes warnings akin to `-Wshorten-64-to-32`.

This full set of warnings here is a tad spammy, but probably more useful than not.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D48954777

fbshipit-source-id: 1ccc07b99d09d1c2d428158149698ffd04025605
2023-09-06 08:16:42 -07:00
Nick Gerleman
f2b4e42ca2 Change how we set cmake policy (#1288)
Summary:
X-link: https://github.com/facebook/react-native/pull/37349

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

Fixes https://github.com/facebook/yoga/issues/1283

New versions of CMake add "policies" which control how the build system acts wrt breaking changes. By default, CMake will emulate the behavior of the version specified in `cmake_minimum_required`.

Setting a policy to true (to opt into new behavior where `cmake_minimum_required` is lower than the current version) seems actually just error out on the old versions.

Googling around, apparently the way I should be doing this is to specify `<policy_max>` as part of `cmake_minimum_required `. https://gitlab.kitware.com/cmake/cmake/-/issues/20392

This should I think use new policies introduced up to 3.26 (what we test on right now), while letting 3.13 be the minimum.

Reviewed By: cortinico

Differential Revision: D45724864

fbshipit-source-id: 120cc2015a043605e7c07ef0459667643a4284b7
2023-05-15 15:21:56 -07:00
Nick Gerleman
e53d1ee28a Enable -Wextra in C++ builds (#1294)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1294

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

Add -Wextra to the build, and fixup some more instances of -Wunused-parameter that it sufaces which were not automatically fixable.

Reviewed By: javache

Differential Revision: D45772846

fbshipit-source-id: 29bf71006f63161521fe5869c3a7d8bf7aae9c81
2023-05-11 09:43:36 -07:00
Nick Gerleman
83c6997f29 Add Global CMake Build and OSS Tests (#1217)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1217

This updates the CMake build present for being able to share options, fixing up flags, etc. A GTest build is added as well, along with a script and VSCode debug target so that OSS contributors can very easily run and debug tests on any OS.

Note that this isn't completely done (need to revise Windows, Mac, documentation), but should be finished enough otherwise for review.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D42406686

fbshipit-source-id: 95e7ba5e4751c496a171785490e85cf0097fa839
2023-01-16 07:56:11 -08:00
Facebook Community Bot
260e60b4b1 Re-sync with internal repository (#1166)
Co-authored-by: Facebook Community Bot <6422482+facebook-github-bot@users.noreply.github.com>
2022-10-11 05:16:06 -07:00
Nick Gerleman
c96564d23d Fix License Headers and Whitespace
Summary: This change applies all Arcanist recommended lint changes, which amounts to changing copyright headers and some cases of whitespace changes.

Reviewed By: yungsters

Differential Revision: D40060899

fbshipit-source-id: b62f9472e6ef58a3fc3d22eed661578a2635cb1f
2022-10-04 13:59:32 -07:00
Andres Suarez
42bba10894 Tidy up license headers
Summary: Changelog: Tidy up license headers

Reviewed By: SidharthGuglani

Differential Revision: D17919414

fbshipit-source-id: 0501b495dc0a42256ca6ba3284a873da1ab175c0
2019-10-15 10:36:38 -07:00
Rain ⁣
a4bdd9cd9b standardize C-like MIT copyright headers throughout fbsource
Summary:
`/*` is the standard throughout open source code. For example, Firefox uses single /*: https://hg.mozilla.org/mozilla-central/file/21d22b2f541258d3d1cf96c7ba5ad73e96e616b5/gfx/ipc/CompositorWidgetVsyncObserver.cpp#l3

In addition, Rust considers `/**` to be a doc comment (similar to Javadoc) and having such a comment at the beginning of the file causes `rustc` to barf.

Note that some JavaScript tooling requires `/**`. This is OK since JavaScript files were not covered by the linter in the first place, but it would be good to have that tooling fixed too.

Reviewed By: zertosh

Differential Revision: D15640366

fbshipit-source-id: b4ed4599071516364d6109720750d6a43304c089
2019-06-06 19:44:16 -07:00
David Aurelio
ab9d06abf5 Apply clang-format rules
Summary:
@public

Formats Yoga's source according to our clang-format configuration

Reviewed By: SidharthGuglani

Differential Revision: D13596650

fbshipit-source-id: c3722d4eafd63b7596a8b1e85c0197e9d2d6cb7d
2019-01-08 12:50:41 -08:00
David Aurelio
b9972cee6e Adjust yearless format for MIT license
Summary:
@public

Adjust license headers throughout the project

Reviewed By: SidharthGuglani

Differential Revision: D13255691

fbshipit-source-id: 98be2aa372a94e7a54a65e3d64e5c6a436b18083
2018-11-29 11:37:52 -08:00
Héctor Ramos
e224a29d1c Update copyright headers to yearless format
Summary: This change drops the year from the copyright headers and the LICENSE file.

Reviewed By: yungsters

Differential Revision: D9727774

fbshipit-source-id: df4fc1e4390733fe774b1a160dd41b4a3d83302a
2018-09-11 15:53:35 -07:00
Jonathan Kim
2b52c73d70 Move yoga_defs.bzl
Reviewed By: mzlee

Differential Revision: D9546736

fbshipit-source-id: ff0c19a33cc72a330bac1e266ad0bb6d7c440e60
2018-08-28 22:06:45 -07:00
Scott Wolchok
765bb85d1e Fix warnings when building benchmark
Summary: There were a few missing prototypes and a -Wshadow violation. Merged YGBenchmark.h into YGBenchmark.c, added static where needed, fixed shadow violation.

Reviewed By: davidaurelio

Differential Revision: D8793124

fbshipit-source-id: c4b2dd348c38aa599169b5e9bea543c172439432
2018-07-11 09:02:34 -07:00
Taras Tsugrii
a67c555320 Fix deprecated glob usage.
Summary: https://our.intern.facebook.com/intern/wiki/Buck/python-to-skylark/

Differential Revision: D8595731

fbshipit-source-id: 0e3046a7fd2a25e9b13462713ae9a008ad546770
2018-06-23 18:27:38 -07:00
Jonathan Kim
3564ccf6e4 Use wrapped cxx_binary
Summary: Introduce `yoga_cxx_binary`

Reviewed By: grzmiel

Differential Revision: D7809271

fbshipit-source-id: 1b66ce59a73e4a63b670f7d3bcadfbb6cbfbc220
2018-04-28 21:32:13 -07:00
Jakub Grzmiel
9b8323ff38 Clean up BUCK files for missing dependencies and tests
Summary: Several of dependencies and tests in repository are missing (e.g. because we don't support building certain library for MacOSX). Clean up those mistakes.

Differential Revision: D7625433

fbshipit-source-id: 332b7ff7eaed82cb52f459921f1ae67b702a1636
2018-04-14 15:35:24 -07:00
Sophie Alpert
a2b6ddb7b1 Update license headers for MIT license
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.

find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.

Reviewed By: TheSavior, yungsters

Differential Revision: D7007050

fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
2018-02-16 18:27:33 -08:00
Taras Tsugrii
dec1172f38 Migrate yoga defs to Skylark syntax.
Summary: https://our.intern.facebook.com/intern/dex/buck/python-to-skylark/

Reviewed By: adamjernst

Differential Revision: D6411822

fbshipit-source-id: 2abe2c183d1b1a28349d0c7bd765754688ec4441
2017-11-27 14:00:52 -08:00
Michael Lee
fc6c85996e Reformat BUCK files
Summary: Reformat BUCK files to better conform with style.

Reviewed By: zertosh

Differential Revision: D5901515

fbshipit-source-id: 93e8c56450f65b691af9017d880e6cf2a2cdb7af
2017-09-25 10:16:22 -07:00
Michael Bolin
47d8d9d22b Apply auto-formatter for BUCK files in fbandroid.
Summary:
For more background, see:

https://fb.facebook.com/groups/303159406399348/permalink/1334977403217538/
https://fburl.com/auto-format-build-files
D4527873

fbshipit-source-id: 278ce6f67f5df830b2218e3aca69be103d3c56a6
2017-02-24 21:44:02 -08:00
Pascal Hartig
326ae15532 Format C/C++ files
Summary: Run new `format.sh`.

Reviewed By: emilsjolander

Differential Revision: D4481501

fbshipit-source-id: 5791bee9919b44282d1549029ff8e078f253ddf8
2017-01-31 09:40:19 -08:00
Emil Sjolander
b11155423c Rename directories
Reviewed By: gkassabli

Differential Revision: D4284681

Summary: Rename csslayout directories to yoga

fbshipit-source-id: f0c6855c2c6e4389b7867f48f72cbb697830fc5a
2016-12-07 05:22:52 -08:00
Emil Sjolander
dda24b1e23 Rename C api
Summary: This renames the core C api to use the new Yoga branding.

Differential Revision: D4259190

fbshipit-source-id: 26c8b356ca464d4304f5f9dc4192bff10cea2dc9
2016-12-03 04:53:38 -08:00
Emil Sjolander
b9feb10420 Rename benchmarks
Summary: new name

Reviewed By: splhack

Differential Revision: D4245765

fbshipit-source-id: c524183ead279ad1d9159a1da2f18fc1b96c2b51
2016-12-02 11:23:20 -08:00
Emil Sjolander
42b6f6b6e5 Rename enums
Summary: new name, start by renaming enums

Differential Revision: D4244360

fbshipit-source-id: c9fcbdd231098c9ff230a6055676bbc7cbd11001
2016-12-02 05:52:59 -08:00
Emil Sjolander
686289814d Rename defs file
Summary: new name

Reviewed By: gkassabli

Differential Revision: D4258291

fbshipit-source-id: 4b9ad8773c68aed25afba57fcfa92721e6acc1a6
2016-12-02 05:22:49 -08:00
Emil Sjolander
31b961d8b3 Revert D4245638: [yoga] Rename defs file
Summary: This reverts commit 14050d02c4298014a5fcadd75c4f364537ec2396

Differential Revision: D4245638

fbshipit-source-id: 5eba4f87cbf5a64e235dd16e038326e916cdda77
2016-11-30 12:37:49 -08:00
Emil Sjolander
ff3d2e1691 Rename defs file
Summary: new name

Reviewed By: gkassabli

Differential Revision: D4245638

fbshipit-source-id: 14050d02c4298014a5fcadd75c4f364537ec2396
2016-11-30 08:07:44 -08:00
Emil Sjolander
087d1f3a82 Fix benchmark
Summary: It was always a mistake to have a measure function here but the recent addition of an assertion made us notice it.

Reviewed By: splhack

Differential Revision: D4156754

fbshipit-source-id: 98fcea6e233cb4f5706ebca37028c8d67edb4c09
2016-11-09 20:22:41 -08:00
Emil Sjolander
df6368e048 Add complex layout to benchmark
Summary: Add a more complex benchmark which actually take a couple milliseconds to perform. This makes it easier to see if optimizations have any effect. More styles should be added later to make sure the benchmarks covers most of the csslayout code.

Reviewed By: gkassabli

Differential Revision: D4101780

fbshipit-source-id: 6bdf703edfbe64c47c77e04ef1ca946f4b75d093
2016-10-31 10:38:02 -07:00
Emil Sjolander
ba20d75992 Fix benchmark
Summary: Benchmark accidentally broke during a refactor

Reviewed By: gkassabli

Differential Revision: D4101776

fbshipit-source-id: 00094837b7856c06c0463c48929f960122c0c8ac
2016-10-31 10:38:02 -07:00
Emil Sjolander
46823878a5 BREAKING - Make first parameter of measure and print functions CSSNodeRef instead of just context
Summary: To perform some JNI optimizations for java we need a reference to the node in the measure function. This updates the API to provide the whole node as input instead of just the context.

Reviewed By: javache

Differential Revision: D4081544

fbshipit-source-id: d49679025cea027cf7b8482898de0a01fe0f9d40
2016-10-27 10:52:57 -07:00
Emil Sjolander
0cc1b83569 Remove nanosleep from benchmark measure and increase loop count
Summary: sleeping in the measure function was done to ensure we were not regressing in double measure calls. This was before we have CSSLayoutMeasureCacheTest though. Let's switch over benchmark to purely benchmark the algorithm and not simulate measure time.

Reviewed By: swolchok

Differential Revision: D4078186

fbshipit-source-id: e1c16806b3c8714e223e1cfcb6c43846f8f6bbb2
2016-10-25 16:23:04 -07:00