Skip to content

Commit a4cc519

Browse files
sherginfacebook-github-bot
authored andcommitted
Fabric: Synthetic benchmarks for prop parsing infra
Summary: And, btw, the tests show that performance of that is not so great: ``` Running /Users/shergin/fbsource/fbobjc/buck-out/cells/fbsource/gen/xplat/js/react-native-github/ReactCommon/fabric/core/benchmarks Run on (12 X 2900 MHz CPU s) CPU Caches: L1 Data 32K (x6) L1 Instruction 32K (x6) L2 Unified 262K (x6) L3 Unified 12582K (x1) -------------------------------------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------------------------------------- propParsingUsingComponentDescriptor 79630 ns 77991 ns 8864 propParsingUsingComponentDescriptorWithNoSourceProps 70200 ns 69099 ns 8362 ``` Which means 70ms per 1000 prop parsing processes. Reviewed By: JoshuaGross, mdvacca Differential Revision: D15608677 fbshipit-source-id: ed4feca489e1243adc73de4741c287256c3aaec3
1 parent 1530228 commit a4cc519

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

ReactCommon/fabric/core/BUCK

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@fbsource//tools/build_defs:fb_xplat_cxx_binary.bzl", "fb_xplat_cxx_binary")
12
load("@fbsource//tools/build_defs/apple:flag_defs.bzl", "get_debug_preprocessor_flags")
23
load(
34
"//tools/build_defs/oss:rn_defs.bzl",
@@ -70,8 +71,8 @@ rn_xplat_cxx_library(
7071

7172
fb_xplat_cxx_test(
7273
name = "tests",
73-
srcs = glob(["tests/**/*.cpp"]),
74-
headers = glob(["tests/**/*.h"]),
74+
srcs = glob(["tests/*.cpp"]),
75+
headers = glob(["tests/*.h"]),
7576
compiler_flags = [
7677
"-fexceptions",
7778
"-frtti",
@@ -86,3 +87,26 @@ fb_xplat_cxx_test(
8687
":core",
8788
],
8889
)
90+
91+
fb_xplat_cxx_binary(
92+
name = "benchmarks",
93+
srcs = glob(["tests/benchmarks/*.cpp"]),
94+
compiler_flags = [
95+
"-fexceptions",
96+
"-frtti",
97+
"-std=c++14",
98+
"-Wall",
99+
"-Wno-unused-variable",
100+
],
101+
contacts = ["[email protected]"],
102+
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
103+
fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + get_apple_inspector_flags(),
104+
platforms = (ANDROID, APPLE, CXX),
105+
visibility = ["PUBLIC"],
106+
deps = [
107+
"fbsource//xplat/third-party/benchmark:benchmark",
108+
react_native_xplat_target("utils:utils"),
109+
react_native_xplat_target("fabric/components/view:view"),
110+
":core",
111+
],
112+
)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include <benchmark/benchmark.h>
9+
#include <folly/dynamic.h>
10+
#include <folly/json.h>
11+
#include <react/components/view/ViewComponentDescriptor.h>
12+
#include <react/core/EventDispatcher.h>
13+
#include <react/core/RawProps.h>
14+
#include <react/utils/ContextContainer.h>
15+
#include <exception>
16+
#include <string>
17+
18+
namespace facebook {
19+
namespace react {
20+
21+
auto contextContainer = std::make_shared<ContextContainer const>();
22+
auto eventDispatcher = std::shared_ptr<EventDispatcher>{nullptr};
23+
auto viewComponentDescriptor =
24+
ViewComponentDescriptor(eventDispatcher, contextContainer);
25+
26+
auto emptyPropsDynamic = folly::parseJson("{}");
27+
auto propsString = std::string{
28+
"{\"flex\": 1, \"padding\": 10, \"position\": \"absolute\", \"display\": \"none\", \"nativeID\": \"some-id\", \"direction\": \"rtl\"}"};
29+
auto propsDynamic = folly::parseJson(propsString);
30+
auto propsStringWithSomeUnsupportedProps = std::string{
31+
"{\"someName1\": 1, \"someName2\": 10, \"someName3\": \"absolute\", \"someName4\": \"none\", \"someName5\": \"some-id\", \"someName6\": \"rtl\"}"};
32+
auto unsupportedPropsDynamic =
33+
folly::parseJson(propsStringWithSomeUnsupportedProps);
34+
35+
auto sourceProps = ViewProps{};
36+
auto sharedSourceProps = ViewShadowNode::defaultSharedProps();
37+
38+
static void emptyPropCreation(benchmark::State &state) {
39+
for (auto _ : state) {
40+
ViewProps{};
41+
}
42+
}
43+
BENCHMARK(emptyPropCreation);
44+
45+
static void propParsingEmptyRawProps(benchmark::State &state) {
46+
for (auto _ : state) {
47+
viewComponentDescriptor.cloneProps(
48+
sharedSourceProps, RawProps{emptyPropsDynamic});
49+
}
50+
}
51+
BENCHMARK(propParsingEmptyRawProps);
52+
53+
static void propParsingRegularRawProps(benchmark::State &state) {
54+
for (auto _ : state) {
55+
viewComponentDescriptor.cloneProps(
56+
sharedSourceProps, RawProps{propsDynamic});
57+
}
58+
}
59+
BENCHMARK(propParsingRegularRawProps);
60+
61+
static void propParsingUnsupportedRawProps(benchmark::State &state) {
62+
for (auto _ : state) {
63+
viewComponentDescriptor.cloneProps(
64+
sharedSourceProps, RawProps{unsupportedPropsDynamic});
65+
}
66+
}
67+
BENCHMARK(propParsingUnsupportedRawProps);
68+
69+
static void propParsingRegularRawPropsWithNoSourceProps(
70+
benchmark::State &state) {
71+
for (auto _ : state) {
72+
viewComponentDescriptor.cloneProps(nullptr, RawProps{propsDynamic});
73+
}
74+
}
75+
BENCHMARK(propParsingRegularRawPropsWithNoSourceProps);
76+
77+
} // namespace react
78+
} // namespace facebook
79+
80+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)