mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: This diff reimplements the prop parsing infrastructure in a part where it interacts with RawProps value. Local synthetic tests show that the new way is 3x faster but the actual production result is quite unpredictable. MobileLab tests show some improvements about 10-20 ms on iPhone 6. In short, the new way is faster because it inverts the lookup order and heavily relies on actual data types (and their properties) that we use. The old approach required about 130 hash-map lookups (where the key is `std::string`) to parse a single *Props object. The new approach prepares concrete-props-specific tables with indexes of coming values ahead of time, iterates over raw data and puts it into those tables, and then performs a lookup in a very efficient manner. Reviewed By: JoshuaGross Differential Revision: D15752968 fbshipit-source-id: 847106e652eb7fc7ef7b99884a6f819ea3b9fd06
60 lines
1.5 KiB
C++
60 lines
1.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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <better/small_vector.h>
|
|
|
|
#include <react/core/RawPropsKey.h>
|
|
#include <react/core/RawPropsPrimitives.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/*
|
|
* A map especially optimized to hold `{name: index}` relations.
|
|
* The implementation is conceptually similar to a classic hash map with a hash
|
|
* function that returns the length of the string.
|
|
* The map is optimized for reads only (the map must be reindexed before a bunch
|
|
* of reads).
|
|
*/
|
|
class RawPropsKeyMap final {
|
|
public:
|
|
/*
|
|
* Stores `value` with by given `key`.
|
|
*/
|
|
void insert(RawPropsKey const &key, RawPropsValueIndex value);
|
|
|
|
/*
|
|
* Reindexes the stored data.
|
|
* Must be called before `at` (after calling a bunch of `add`s).
|
|
*/
|
|
void reindex();
|
|
|
|
/*
|
|
* Finds and returns the `value` (some index) by given `key`.
|
|
* Returns `kRawPropsValueIndexEmpty` if the value wan't found.
|
|
*/
|
|
RawPropsValueIndex at(char const *name, RawPropsPropNameLength length);
|
|
|
|
private:
|
|
static int comparator(void const *lhs, void const *rhs);
|
|
|
|
struct Item {
|
|
RawPropsValueIndex value;
|
|
RawPropsPropNameLength length;
|
|
char name[kPropNameLengthHardCap];
|
|
};
|
|
|
|
better::small_vector<Item, kNumberOfExplicitlySpecifedPropsSoftCap> items_{};
|
|
better::small_vector<RawPropsPropNameLength, kPropNameLengthHardCap>
|
|
buckets_{};
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|