Skip to content

Commit

Permalink
Fabric: Synthetic benchmarks for prop parsing infra
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shergin authored and facebook-github-bot committed Jun 4, 2019
1 parent 1530228 commit a4cc519
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
28 changes: 26 additions & 2 deletions ReactCommon/fabric/core/BUCK
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@fbsource//tools/build_defs:fb_xplat_cxx_binary.bzl", "fb_xplat_cxx_binary")
load("@fbsource//tools/build_defs/apple:flag_defs.bzl", "get_debug_preprocessor_flags")
load(
"//tools/build_defs/oss:rn_defs.bzl",
Expand Down Expand Up @@ -70,8 +71,8 @@ rn_xplat_cxx_library(

fb_xplat_cxx_test(
name = "tests",
srcs = glob(["tests/**/*.cpp"]),
headers = glob(["tests/**/*.h"]),
srcs = glob(["tests/*.cpp"]),
headers = glob(["tests/*.h"]),
compiler_flags = [
"-fexceptions",
"-frtti",
Expand All @@ -86,3 +87,26 @@ fb_xplat_cxx_test(
":core",
],
)

fb_xplat_cxx_binary(
name = "benchmarks",
srcs = glob(["tests/benchmarks/*.cpp"]),
compiler_flags = [
"-fexceptions",
"-frtti",
"-std=c++14",
"-Wall",
"-Wno-unused-variable",
],
contacts = ["oncall+react_native@xmail.facebook.com"],
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + get_apple_inspector_flags(),
platforms = (ANDROID, APPLE, CXX),
visibility = ["PUBLIC"],
deps = [
"fbsource//xplat/third-party/benchmark:benchmark",
react_native_xplat_target("utils:utils"),
react_native_xplat_target("fabric/components/view:view"),
":core",
],
)
80 changes: 80 additions & 0 deletions ReactCommon/fabric/core/tests/benchmarks/RawPropsBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <benchmark/benchmark.h>
#include <folly/dynamic.h>
#include <folly/json.h>
#include <react/components/view/ViewComponentDescriptor.h>
#include <react/core/EventDispatcher.h>
#include <react/core/RawProps.h>
#include <react/utils/ContextContainer.h>
#include <exception>
#include <string>

namespace facebook {
namespace react {

auto contextContainer = std::make_shared<ContextContainer const>();
auto eventDispatcher = std::shared_ptr<EventDispatcher>{nullptr};
auto viewComponentDescriptor =
ViewComponentDescriptor(eventDispatcher, contextContainer);

auto emptyPropsDynamic = folly::parseJson("{}");
auto propsString = std::string{
"{\"flex\": 1, \"padding\": 10, \"position\": \"absolute\", \"display\": \"none\", \"nativeID\": \"some-id\", \"direction\": \"rtl\"}"};
auto propsDynamic = folly::parseJson(propsString);
auto propsStringWithSomeUnsupportedProps = std::string{
"{\"someName1\": 1, \"someName2\": 10, \"someName3\": \"absolute\", \"someName4\": \"none\", \"someName5\": \"some-id\", \"someName6\": \"rtl\"}"};
auto unsupportedPropsDynamic =
folly::parseJson(propsStringWithSomeUnsupportedProps);

auto sourceProps = ViewProps{};
auto sharedSourceProps = ViewShadowNode::defaultSharedProps();

static void emptyPropCreation(benchmark::State &state) {
for (auto _ : state) {
ViewProps{};
}
}
BENCHMARK(emptyPropCreation);

static void propParsingEmptyRawProps(benchmark::State &state) {
for (auto _ : state) {
viewComponentDescriptor.cloneProps(
sharedSourceProps, RawProps{emptyPropsDynamic});
}
}
BENCHMARK(propParsingEmptyRawProps);

static void propParsingRegularRawProps(benchmark::State &state) {
for (auto _ : state) {
viewComponentDescriptor.cloneProps(
sharedSourceProps, RawProps{propsDynamic});
}
}
BENCHMARK(propParsingRegularRawProps);

static void propParsingUnsupportedRawProps(benchmark::State &state) {
for (auto _ : state) {
viewComponentDescriptor.cloneProps(
sharedSourceProps, RawProps{unsupportedPropsDynamic});
}
}
BENCHMARK(propParsingUnsupportedRawProps);

static void propParsingRegularRawPropsWithNoSourceProps(
benchmark::State &state) {
for (auto _ : state) {
viewComponentDescriptor.cloneProps(nullptr, RawProps{propsDynamic});
}
}
BENCHMARK(propParsingRegularRawPropsWithNoSourceProps);

} // namespace react
} // namespace facebook

BENCHMARK_MAIN();

0 comments on commit a4cc519

Please sign in to comment.