wip: feeling goodish about scheduler

This commit is contained in:
Jonathan Kelley committed 2021-08-26 03:33:38 -04:00
1 parent bcaa76a37f
commit 5f63eda294
2 files changed
+50 -33

No files matched your search

+4
View File
@@ -55,6 +55,10 @@ impl<'bump> DiffStack<'bump> {
} }
} }
pub fn is_empty(&self) -> bool {
self.instructions.is_empty()
}
pub fn pop(&mut self) -> Option<DiffInstruction<'bump>> { pub fn pop(&mut self) -> Option<DiffInstruction<'bump>> {
self.instructions.pop() self.instructions.pop()
} }
+46 -33
View File
@@ -531,49 +531,60 @@ impl Scheduler {
use futures_util::future::{select, Either}; use futures_util::future::{select, Either};
// if let Some(state) = current_lane.saved_state.take() { // We have to split away some parts of ourself - current lane is borrowed mutably
// let mut machine = unsafe { state.promote(&self) };
// machine.work().await;
// } else {
if let Some(scope) = current_lane.dirty_scopes.pop() {
let (mut saved_work, work_complete): (SavedDiffWork<'static>, bool) = {
let shared = SharedVdom { let shared = SharedVdom {
channel: self.channel.clone(), channel: self.channel.clone(),
components: unsafe { &mut *self.components.get() }, components: unsafe { &mut *self.components.get() },
elements: &mut self.raw_elements, elements: &mut self.raw_elements,
}; };
let mut machine = DiffMachine::new(Mutations::new(), shared);
let work_complete = { let mut state = current_lane.saved_state.take().unwrap();
let fut = machine.diff_scope(scope); let mut machine = unsafe { state.promote(shared) };
pin_mut!(fut);
match select(fut, &mut deadline).await {
Either::Left((work, _other)) => {
//
true
}
Either::Right((deadline, _other)) => {
//
false
}
}
};
let saved = machine.save(); if machine.stack.is_empty() {
let extended: SavedDiffWork<'static> = unsafe { transmute(saved) }; // if let Some(scope) = current_lane.dirty_scopes.pop() {
(extended, work_complete) // let component = self.components.get_mut().get_mut(scope.0).unwrap();
}; // let (old, new) = (component.frames.wip_head(), component.frames.fin_head());
// machine.stack.push(DiffInstruction::DiffNode { new, old });
// release the stack borrow of ourself // } else {
// }
if work_complete {
for scope in saved_work.seen_scopes.drain() {
current_lane.dirty_scopes.remove(&scope);
}
} else { } else {
} }
// if let Some(state) = current_lane.saved_state.take() {
// let mut machine = unsafe { state.promote(&self) };
// machine.work().await;
// } else {
// if let Some(scope) = current_lane.dirty_scopes.pop() {
//
// let work_complete = {
// let fut = machine.diff_scope(scope);
// pin_mut!(fut);
// match select(fut, &mut deadline).await {
// Either::Left((work, _other)) => {
// //
// true
// } // }
}; // Either::Right((deadline, _other)) => {
// //
// false
// }
// }
// };
// let mut saved = unsafe { machine.save().extend() };
// // release the stack borrow of ourself
// if work_complete {
// for scope in saved.seen_scopes.drain() {
// current_lane.dirty_scopes.remove(&scope);
// }
// } else {
// }
// }
// };
// let mut new_mutations = Mutations::new(); // let mut new_mutations = Mutations::new();
// match self.work_with_deadline(&mut deadline).await { // match self.work_with_deadline(&mut deadline).await {
@@ -679,6 +690,7 @@ impl Scheduler {
pub struct PriortySystem { pub struct PriortySystem {
pub dirty_scopes: IndexSet<ScopeId>, pub dirty_scopes: IndexSet<ScopeId>,
pub saved_state: Option<SavedDiffWork<'static>>, pub saved_state: Option<SavedDiffWork<'static>>,
pub in_progress: bool,
} }
impl PriortySystem { impl PriortySystem {
@@ -686,6 +698,7 @@ impl PriortySystem {
Self { Self {
saved_state: None, saved_state: None,
dirty_scopes: Default::default(), dirty_scopes: Default::default(),
in_progress: false,
} }
} }