perf: use absl::flat_hash_map
instead of std::unordered_map
(#46217)
* perf: make ElectronUsbDelegate::controller_map_ an absl::flat_hash_map Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: make ElectronSerialDelegate::controller_map_ an absl::flat_hash_map Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: make ElectronHidDelegate::controller_map_ an absl::flat_hash_map Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: make FrameTreeNodeIdMap an absl::flat_hash_map Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: make AutofillDriverFactory::driver_map_ an absl::flat_hash_map Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: make asar::Archive::external_files_ an absl::flat_hash_map Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: make VersionIdMap an absl::flat_hash_map Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: make ObjectCache::proxy_map_ an absl::flat_hash_map Co-authored-by: Charles Kerr <charles@charleskerr.com> * docs: add TODO to investigate absl map in KeyWeakMap Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
e1b2b8ef0c
commit
76fa5b7af1
9 changed files with 24 additions and 24 deletions
|
@ -5,7 +5,6 @@
|
||||||
#include "shell/browser/api/electron_api_service_worker_main.h"
|
#include "shell/browser/api/electron_api_service_worker_main.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
|
@ -28,6 +27,7 @@
|
||||||
#include "shell/common/gin_helper/promise.h"
|
#include "shell/common/gin_helper/promise.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "shell/common/v8_util.h"
|
#include "shell/common/v8_util.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -58,10 +58,9 @@ std::optional<content::ServiceWorkerVersionBaseInfo> GetLiveVersionInfo(
|
||||||
namespace electron::api {
|
namespace electron::api {
|
||||||
|
|
||||||
// ServiceWorkerKey -> ServiceWorkerMain*
|
// ServiceWorkerKey -> ServiceWorkerMain*
|
||||||
typedef std::unordered_map<ServiceWorkerKey,
|
using VersionIdMap = absl::flat_hash_map<ServiceWorkerKey,
|
||||||
ServiceWorkerMain*,
|
ServiceWorkerMain*,
|
||||||
ServiceWorkerKey::Hasher>
|
ServiceWorkerKey::Hasher>;
|
||||||
VersionIdMap;
|
|
||||||
|
|
||||||
VersionIdMap& GetVersionIdMap() {
|
VersionIdMap& GetVersionIdMap() {
|
||||||
static base::NoDestructor<VersionIdMap> instance;
|
static base::NoDestructor<VersionIdMap> instance;
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include "shell/browser/api/electron_api_web_frame_main.h"
|
#include "shell/browser/api/electron_api_web_frame_main.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -36,6 +35,7 @@
|
||||||
#include "shell/common/gin_helper/promise.h"
|
#include "shell/common/gin_helper/promise.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
#include "shell/common/v8_util.h"
|
#include "shell/common/v8_util.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ namespace electron::api {
|
||||||
// Using FrameTreeNode allows us to track frame across navigations. This
|
// Using FrameTreeNode allows us to track frame across navigations. This
|
||||||
// is most similar to how <iframe> works.
|
// is most similar to how <iframe> works.
|
||||||
using FrameTreeNodeIdMap =
|
using FrameTreeNodeIdMap =
|
||||||
std::unordered_map<content::FrameTreeNodeId, WebFrameMain*>;
|
absl::flat_hash_map<content::FrameTreeNodeId, WebFrameMain*>;
|
||||||
|
|
||||||
// Token -> WebFrameMain*
|
// Token -> WebFrameMain*
|
||||||
// Maps exact RFH to a WebFrameMain instance.
|
// Maps exact RFH to a WebFrameMain instance.
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
#define ELECTRON_SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_
|
#define ELECTRON_SHELL_BROWSER_ELECTRON_AUTOFILL_DRIVER_FACTORY_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
#include "base/functional/callback_forward.h"
|
#include "base/functional/callback_forward.h"
|
||||||
#include "content/public/browser/web_contents_observer.h"
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
#include "content/public/browser/web_contents_user_data.h"
|
#include "content/public/browser/web_contents_user_data.h"
|
||||||
#include "shell/common/api/api.mojom.h"
|
#include "shell/common/api/api.mojom.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
@ -49,7 +49,8 @@ class AutofillDriverFactory
|
||||||
explicit AutofillDriverFactory(content::WebContents* web_contents);
|
explicit AutofillDriverFactory(content::WebContents* web_contents);
|
||||||
friend class content::WebContentsUserData<AutofillDriverFactory>;
|
friend class content::WebContentsUserData<AutofillDriverFactory>;
|
||||||
|
|
||||||
std::unordered_map<content::RenderFrameHost*, std::unique_ptr<AutofillDriver>>
|
absl::flat_hash_map<content::RenderFrameHost*,
|
||||||
|
std::unique_ptr<AutofillDriver>>
|
||||||
driver_map_;
|
driver_map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,13 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/containers/flat_map.h"
|
#include "base/containers/flat_map.h"
|
||||||
#include "content/public/browser/hid_chooser.h"
|
#include "content/public/browser/hid_chooser.h"
|
||||||
#include "content/public/browser/hid_delegate.h"
|
#include "content/public/browser/hid_delegate.h"
|
||||||
#include "services/device/public/mojom/hid.mojom-forward.h"
|
#include "services/device/public/mojom/hid.mojom-forward.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
|
||||||
#include "third_party/blink/public/mojom/hid/hid.mojom-forward.h"
|
#include "third_party/blink/public/mojom/hid/hid.mojom-forward.h"
|
||||||
#include "url/origin.h"
|
#include "url/origin.h"
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ class ElectronHidDelegate : public content::HidDelegate {
|
||||||
std::vector<blink::mojom::HidDeviceFilterPtr> exclusion_filters,
|
std::vector<blink::mojom::HidDeviceFilterPtr> exclusion_filters,
|
||||||
content::HidChooser::Callback callback);
|
content::HidChooser::Callback callback);
|
||||||
|
|
||||||
std::unordered_map<content::RenderFrameHost*,
|
absl::flat_hash_map<content::RenderFrameHost*,
|
||||||
std::unique_ptr<HidChooserController>>
|
std::unique_ptr<HidChooserController>>
|
||||||
controller_map_;
|
controller_map_;
|
||||||
|
|
||||||
base::WeakPtrFactory<ElectronHidDelegate> weak_factory_{this};
|
base::WeakPtrFactory<ElectronHidDelegate> weak_factory_{this};
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#define ELECTRON_SHELL_BROWSER_SERIAL_ELECTRON_SERIAL_DELEGATE_H_
|
#define ELECTRON_SHELL_BROWSER_SERIAL_ELECTRON_SERIAL_DELEGATE_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
|
@ -15,6 +14,7 @@
|
||||||
#include "content/public/browser/serial_delegate.h"
|
#include "content/public/browser/serial_delegate.h"
|
||||||
#include "shell/browser/serial/serial_chooser_context.h"
|
#include "shell/browser/serial/serial_chooser_context.h"
|
||||||
#include "shell/browser/serial/serial_chooser_controller.h"
|
#include "shell/browser/serial/serial_chooser_controller.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
@ -77,8 +77,8 @@ class ElectronSerialDelegate : public content::SerialDelegate,
|
||||||
port_observation_{this};
|
port_observation_{this};
|
||||||
base::ObserverList<content::SerialDelegate::Observer> observer_list_;
|
base::ObserverList<content::SerialDelegate::Observer> observer_list_;
|
||||||
|
|
||||||
std::unordered_map<content::RenderFrameHost*,
|
absl::flat_hash_map<content::RenderFrameHost*,
|
||||||
std::unique_ptr<SerialChooserController>>
|
std::unique_ptr<SerialChooserController>>
|
||||||
controller_map_;
|
controller_map_;
|
||||||
|
|
||||||
base::WeakPtrFactory<ElectronSerialDelegate> weak_factory_{this};
|
base::WeakPtrFactory<ElectronSerialDelegate> weak_factory_{this};
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/containers/span.h"
|
#include "base/containers/span.h"
|
||||||
|
@ -17,6 +16,7 @@
|
||||||
#include "services/device/public/mojom/usb_device.mojom-forward.h"
|
#include "services/device/public/mojom/usb_device.mojom-forward.h"
|
||||||
#include "services/device/public/mojom/usb_enumeration_options.mojom-forward.h"
|
#include "services/device/public/mojom/usb_enumeration_options.mojom-forward.h"
|
||||||
#include "services/device/public/mojom/usb_manager.mojom-forward.h"
|
#include "services/device/public/mojom/usb_manager.mojom-forward.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
|
||||||
#include "third_party/blink/public/mojom/usb/web_usb_service.mojom.h"
|
#include "third_party/blink/public/mojom/usb/web_usb_service.mojom.h"
|
||||||
#include "url/origin.h"
|
#include "url/origin.h"
|
||||||
|
|
||||||
|
@ -111,8 +111,8 @@ class ElectronUsbDelegate : public content::UsbDelegate {
|
||||||
base::flat_map<content::BrowserContext*, std::unique_ptr<ContextObservation>>
|
base::flat_map<content::BrowserContext*, std::unique_ptr<ContextObservation>>
|
||||||
observations_;
|
observations_;
|
||||||
|
|
||||||
std::unordered_map<content::RenderFrameHost*,
|
absl::flat_hash_map<content::RenderFrameHost*,
|
||||||
std::unique_ptr<UsbChooserController>>
|
std::unique_ptr<UsbChooserController>>
|
||||||
controller_map_;
|
controller_map_;
|
||||||
|
|
||||||
base::WeakPtrFactory<ElectronUsbDelegate> weak_factory_{this};
|
base::WeakPtrFactory<ElectronUsbDelegate> weak_factory_{this};
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
@ -17,6 +16,7 @@
|
||||||
#include "base/files/file_path.h"
|
#include "base/files/file_path.h"
|
||||||
#include "base/synchronization/lock.h"
|
#include "base/synchronization/lock.h"
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
|
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
|
||||||
|
|
||||||
namespace asar {
|
namespace asar {
|
||||||
|
|
||||||
|
@ -110,8 +110,8 @@ class Archive {
|
||||||
|
|
||||||
// Cached external temporary files.
|
// Cached external temporary files.
|
||||||
base::Lock external_files_lock_;
|
base::Lock external_files_lock_;
|
||||||
std::unordered_map<base::FilePath::StringType,
|
absl::flat_hash_map<base::FilePath::StringType,
|
||||||
std::unique_ptr<ScopedTemporaryFile>>
|
std::unique_ptr<ScopedTemporaryFile>>
|
||||||
external_files_;
|
external_files_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ class KeyWeakMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map of stored objects.
|
// Map of stored objects.
|
||||||
|
// TODO(ckerr): can absl::flat_hash_map be used safely here?
|
||||||
std::unordered_map<K, Mapped> map_;
|
std::unordered_map<K, Mapped> map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
#ifndef ELECTRON_SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
|
#ifndef ELECTRON_SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
|
||||||
#define ELECTRON_SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
|
#define ELECTRON_SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
|
||||||
|
|
||||||
#include <unordered_map>
|
#include "third_party/abseil-cpp/absl/container/flat_hash_map.h"
|
||||||
|
|
||||||
#include "v8/include/v8-local-handle.h"
|
#include "v8/include/v8-local-handle.h"
|
||||||
#include "v8/include/v8-object.h"
|
#include "v8/include/v8-object.h"
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ class ObjectCache final {
|
||||||
};
|
};
|
||||||
|
|
||||||
// from_object ==> proxy_value
|
// from_object ==> proxy_value
|
||||||
std::unordered_map<v8::Local<v8::Object>, v8::Local<v8::Value>, Hash>
|
absl::flat_hash_map<v8::Local<v8::Object>, v8::Local<v8::Value>, Hash>
|
||||||
proxy_map_;
|
proxy_map_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue