mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
a4cc519a52
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
81 lines
2.5 KiB
C++
81 lines
2.5 KiB
C++
/**
|
|
* 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();
|