-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
1530228
commit a4cc519
Showing
2 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
ReactCommon/fabric/core/tests/benchmarks/RawPropsBenchmark.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |