Skip to content

Commit ca2eebd

Browse files
committed
core::rt: Add some notes about optimizations
1 parent f4ed554 commit ca2eebd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libstd/rt/sched.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ use rt::rtio::{IoFactoryObject, RemoteCallback};
2929
/// on a single thread. When the scheduler is running it is owned by
3030
/// thread local storage and the running task is owned by the
3131
/// scheduler.
32+
///
33+
/// XXX: This creates too many callbacks to run_sched_once, resulting
34+
/// in too much allocation and too many events.
3235
pub struct Scheduler {
3336
/// A queue of available work. Under a work-stealing policy there
3437
/// is one per Scheduler.
@@ -143,6 +146,10 @@ pub impl Scheduler {
143146

144147
fn run_sched_once() {
145148

149+
// First, check the message queue for instructions.
150+
// XXX: perf. Check for messages without atomics.
151+
// It's ok if we miss messages occasionally, as long as
152+
// we sync and check again before sleeping.
146153
let sched = Local::take::<Scheduler>();
147154
if sched.interpret_message_queue() {
148155
// We performed a scheduling action. There may be other work
@@ -153,6 +160,7 @@ pub impl Scheduler {
153160
return;
154161
}
155162

163+
// Now, look in the work queue for tasks to run
156164
let sched = Local::take::<Scheduler>();
157165
if sched.resume_task_from_queue() {
158166
// We performed a scheduling action. There may be other work
@@ -198,6 +206,12 @@ pub impl Scheduler {
198206
self.event_loop.callback(Scheduler::run_sched_once);
199207

200208
// We've made work available. Notify a sleeping scheduler.
209+
// XXX: perf. Check for a sleeper without synchronizing memory.
210+
// It's not critical that we always find it.
211+
// XXX: perf. If there's a sleeper then we might as well just send
212+
// it the task directly instead of pushing it to the
213+
// queue. That is essentially the intent here and it is less
214+
// work.
201215
match self.sleeper_list.pop() {
202216
Some(handle) => {
203217
let mut handle = handle;

0 commit comments

Comments
 (0)