Skip to content

Commit 46d5fdb

Browse files
committed
Bug 1879197 - Part 9: Use a more efficient type for newly added queues, r=ipc-reviewers,mccr8
The changes imported from chromium used a few base::queue instances as temporary stores. This was translated to the API-compatible std::queue when importing. As all of these queues are only appended to, and then consumed fully, these values can be swapped to use the much more memory-efficient std::vector type. Depends on D201112 Differential Revision: https://phabricator.services.mozilla.com/D201113
1 parent db78973 commit 46d5fdb

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

ipc/chromium/src/mojo/core/ports/node.cc

+13-14
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,8 @@ int Node::OnObserveProxy(const PortRef& port_ref,
816816
event->set_control_sequence_num(
817817
port->next_control_sequence_num_to_send++);
818818
if (port->state == Port::kBuffering) {
819-
port->control_message_queue.push({event_target_node, std::move(event)});
819+
port->control_message_queue.push_back(
820+
{event_target_node, std::move(event)});
820821
} else {
821822
event_to_forward = std::move(event);
822823
}
@@ -961,7 +962,7 @@ int Node::OnObserveClosure(const PortRef& port_ref,
961962
peer_node_name = port->peer_node_name;
962963

963964
if (port->state == Port::kBuffering) {
964-
port->control_message_queue.push({peer_node_name, std::move(event)});
965+
port->control_message_queue.push_back({peer_node_name, std::move(event)});
965966
}
966967
}
967968

@@ -1074,7 +1075,7 @@ int Node::OnUserMessageReadAckRequest(
10741075
port->next_control_sequence_num_to_send++, current_sequence_num);
10751076

10761077
if (port->state == Port::kBuffering) {
1077-
port->control_message_queue.push(
1078+
port->control_message_queue.push_back(
10781079
{peer_node_name, std::move(event_to_send)});
10791080
}
10801081

@@ -1519,7 +1520,7 @@ int Node::PrepareToForwardUserMessage(const PortRef& forwarding_port_ref,
15191520
UserMessageEvent* message,
15201521
NodeName* forward_to_node) {
15211522
bool target_is_remote = false;
1522-
std::queue<PendingUpdatePreviousPeer> peer_update_events;
1523+
std::vector<PendingUpdatePreviousPeer> peer_update_events;
15231524

15241525
for (;;) {
15251526
NodeName target_node_name;
@@ -1628,7 +1629,7 @@ int Node::PrepareToForwardUserMessage(const PortRef& forwarding_port_ref,
16281629
.from_port = attached_port_refs[i].name()};
16291630
ConvertToProxy(port, target_node_name, message->ports() + i,
16301631
port_descriptors + i, &update_event);
1631-
peer_update_events.push(update_event);
1632+
peer_update_events.push_back(update_event);
16321633
}
16331634
}
16341635
}
@@ -1648,9 +1649,7 @@ int Node::PrepareToForwardUserMessage(const PortRef& forwarding_port_ref,
16481649
break;
16491650
}
16501651

1651-
while (!peer_update_events.empty()) {
1652-
auto pending_update_event = peer_update_events.front();
1653-
peer_update_events.pop();
1652+
for (auto& pending_update_event : peer_update_events) {
16541653
delegate_->ForwardEvent(
16551654
pending_update_event.receiver,
16561655
mozilla::MakeUnique<UpdatePreviousPeerEvent>(
@@ -1679,7 +1678,7 @@ int Node::PrepareToForwardUserMessage(const PortRef& forwarding_port_ref,
16791678
}
16801679

16811680
int Node::BeginProxying(const PortRef& port_ref) {
1682-
std::queue<std::pair<NodeName, ScopedEvent>> control_message_queue;
1681+
std::vector<std::pair<NodeName, ScopedEvent>> control_message_queue;
16831682
{
16841683
SinglePortLocker locker(&port_ref);
16851684
auto* port = locker.port();
@@ -1690,12 +1689,12 @@ int Node::BeginProxying(const PortRef& port_ref) {
16901689
std::swap(port->control_message_queue, control_message_queue);
16911690
}
16921691

1693-
while (!control_message_queue.empty()) {
1694-
auto node_event_pair = std::move(control_message_queue.front());
1695-
control_message_queue.pop();
1696-
delegate_->ForwardEvent(node_event_pair.first,
1697-
std::move(node_event_pair.second));
1692+
for (auto& [control_message_node_name, control_message_event] :
1693+
control_message_queue) {
1694+
delegate_->ForwardEvent(control_message_node_name,
1695+
std::move(control_message_event));
16981696
}
1697+
control_message_queue.clear();
16991698

17001699
int rv = ForwardUserMessagesFromProxy(port_ref);
17011700
if (rv != OK) {

ipc/chromium/src/mojo/core/ports/node.h

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <stddef.h>
99
#include <stdint.h>
1010

11-
#include <queue>
1211
#include <unordered_map>
1312

1413
#include "mojo/core/ports/event.h"

ipc/chromium/src/mojo/core/ports/port.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <map>
99
#include <memory>
10-
#include <queue>
1110
#include <utility>
1211
#include <vector>
1312

@@ -203,7 +202,7 @@ class Port {
203202
MessageQueue message_queue;
204203

205204
// Buffer outgoing control messages while this port is in kBuffering state.
206-
std::queue<std::pair<NodeName, ScopedEvent>> control_message_queue;
205+
std::vector<std::pair<NodeName, ScopedEvent>> control_message_queue;
207206

208207
// In some edge cases, a Node may need to remember to route a single special
209208
// event upon destruction of this (proxying) Port. That event is stashed here

0 commit comments

Comments
 (0)