Skip to content

Commit 04950cd

Browse files
committed
eliminate quadratic waker lookup
1 parent d1693d8 commit 04950cd

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/runtime/reactor.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,12 @@ impl Reactor {
141141
// we need to be able to associate the index with the right waker.
142142

143143
// We start by iterating over the pollables, and keeping note of which
144-
// pollable belongs to which waker index
145-
let mut indexes = Vec::with_capacity(reactor.wakers.len());
144+
// pollable belongs to which waker
145+
let mut indexed_wakers = Vec::with_capacity(reactor.wakers.len());
146146
let mut targets = Vec::with_capacity(reactor.wakers.len());
147-
for waitee in reactor.wakers.keys() {
147+
for (waitee, waker) in reactor.wakers.iter() {
148148
let pollable_index = waitee.pollable.0.key;
149-
// FIXME: instead of storing the indexes, we can actually just stick the waker in here,
150-
// and make the quadratic lookup at the end of this function into a linear lookup.
151-
indexes.push(pollable_index);
149+
indexed_wakers.push(waker);
152150
targets.push(&reactor.pollables[pollable_index.0]);
153151
}
154152

@@ -166,17 +164,12 @@ impl Reactor {
166164
// to convert it back to the right keys for the wakers. Earlier we
167165
// established a positional index -> waker key relationship, so we can
168166
// go right ahead and perform a lookup there.
169-
let ready_keys = ready_indexes
167+
let ready_wakers = ready_indexes
170168
.into_iter()
171-
.map(|index| indexes[index as usize]);
169+
.map(|index| indexed_wakers[index as usize]);
172170

173-
// FIXME this doesn't have to be quadratic.
174-
for key in ready_keys {
175-
for (waitee, waker) in reactor.wakers.iter() {
176-
if waitee.pollable.0.key == key {
177-
waker.wake_by_ref()
178-
}
179-
}
171+
for waker in ready_wakers {
172+
waker.wake_by_ref()
180173
}
181174
}
182175

0 commit comments

Comments
 (0)