-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: use an array for faster binding data lookup
Locally the hashing of the binding names sometimes has significant presence in the profile of bindings, because there can be collisions, which makes the cost of adding a new binding data non-trivial, but it's wasteful to spend time on hashing them or dealing with collisions at all, since we can just use the EmbedderObjectType enum as the key, as the string names are not actually used beyond debugging purposes and can be easily matched with a macro. And since we can just use the enum as the key, we do not even need the map and can just use an array with the enum as indices for the lookup. PR-URL: #46620 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
- Loading branch information
1 parent
68dde38
commit c0fcad3
Showing
16 changed files
with
117 additions
and
56 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
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
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
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,69 @@ | ||
#ifndef SRC_BASE_OBJECT_TYPES_H_ | ||
#define SRC_BASE_OBJECT_TYPES_H_ | ||
|
||
#include <cinttypes> | ||
|
||
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
|
||
namespace node { | ||
// List of internalBinding() data wrappers. The first argument should match | ||
// what the class passes to SET_BINDING_ID(), the second argument should match | ||
// the C++ class name. | ||
#define SERIALIZABLE_BINDING_TYPES(V) \ | ||
V(fs_binding_data, fs::BindingData) \ | ||
V(v8_binding_data, v8_utils::BindingData) \ | ||
V(blob_binding_data, BlobBindingData) \ | ||
V(process_binding_data, process::BindingData) | ||
|
||
#define UNSERIALIZABLE_BINDING_TYPES(V) \ | ||
V(http2_binding_data, http2::BindingData) \ | ||
V(http_parser_binding_data, http_parser::BindingData) | ||
|
||
// List of (non-binding) BaseObjects that are serializable in the snapshot. | ||
// The first argument should match what the type passes to | ||
// SET_OBJECT_ID(), the second argument should match the C++ class | ||
// name. | ||
#define SERIALIZABLE_NON_BINDING_TYPES(V) \ | ||
V(util_weak_reference, util::WeakReference) | ||
|
||
// Helper list of all binding data wrapper types. | ||
#define BINDING_TYPES(V) \ | ||
SERIALIZABLE_BINDING_TYPES(V) \ | ||
UNSERIALIZABLE_BINDING_TYPES(V) | ||
|
||
// Helper list of all BaseObjects that implement snapshot support. | ||
#define SERIALIZABLE_OBJECT_TYPES(V) \ | ||
SERIALIZABLE_BINDING_TYPES(V) \ | ||
SERIALIZABLE_NON_BINDING_TYPES(V) | ||
|
||
#define V(TypeId, NativeType) k_##TypeId, | ||
enum class BindingDataType : uint8_t { BINDING_TYPES(V) kBindingDataTypeCount }; | ||
// Make sure that we put the bindings first so that we can also use the enums | ||
// for the bindings as index to the binding data store. | ||
enum class EmbedderObjectType : uint8_t { | ||
BINDING_TYPES(V) SERIALIZABLE_NON_BINDING_TYPES(V) | ||
// We do not need to know about all the unserializable non-binding types for | ||
// now so we do not list them. | ||
kEmbedderObjectTypeCount | ||
}; | ||
#undef V | ||
|
||
// For now, BaseObjects only need to call this when they implement snapshot | ||
// support. | ||
#define SET_OBJECT_ID(TypeId) \ | ||
static constexpr EmbedderObjectType type_int = EmbedderObjectType::k_##TypeId; | ||
|
||
// Binding data should call this so that they can be looked up from the binding | ||
// data store. | ||
#define SET_BINDING_ID(TypeId) \ | ||
static constexpr BindingDataType binding_type_int = \ | ||
BindingDataType::k_##TypeId; \ | ||
SET_OBJECT_ID(TypeId) \ | ||
static_assert(static_cast<uint8_t>(type_int) == \ | ||
static_cast<uint8_t>(binding_type_int)); | ||
|
||
} // namespace node | ||
|
||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
|
||
#endif // SRC_BASE_OBJECT_TYPES_H_ |
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
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
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
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
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
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
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
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
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
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
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
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