1343: optimization: cancel backlog in onEnter r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-05-29 13:05:58 +00:00
commit cb21a21998
2 changed files with 16 additions and 3 deletions

View file

@ -1,7 +1,7 @@
mod handlers;
mod subscriptions;
use std::{fmt, path::PathBuf, sync::Arc, time::Instant};
use std::{fmt, path::PathBuf, sync::Arc, time::Instant, any::TypeId};
use crossbeam_channel::{select, unbounded, Receiver, RecvError, Sender};
use failure::{bail, format_err};
@ -447,14 +447,14 @@ struct PoolDispatcher<'a> {
req: Option<RawRequest>,
res: Option<u64>,
pool: &'a ThreadPool,
world: &'a ServerWorldState,
world: &'a mut ServerWorldState,
sender: &'a Sender<Task>,
}
impl<'a> PoolDispatcher<'a> {
fn on<R>(&mut self, f: fn(ServerWorld, R::Params) -> Result<R::Result>) -> Result<&mut Self>
where
R: req::Request,
R: req::Request + 'static,
R::Params: DeserializeOwned + Send + 'static,
R::Result: Serialize + 'static,
{
@ -464,6 +464,15 @@ impl<'a> PoolDispatcher<'a> {
};
match req.cast::<R>() {
Ok((id, params)) => {
// Real time requests block user typing, so we should react quickly to them.
// Currently this means that we try to cancel background jobs if we don't have
// a spare thread.
let is_real_time = TypeId::of::<R>() == TypeId::of::<req::JoinLines>()
|| TypeId::of::<R>() == TypeId::of::<req::OnEnter>();
if self.pool.queued_count() > 0 && is_real_time {
self.world.cancel_requests();
}
let world = self.world.snapshot();
let sender = self.sender.clone();
self.pool.execute(move || {

View file

@ -149,6 +149,10 @@ impl ServerWorldState {
self.analysis_host.apply_change(change);
}
pub fn cancel_requests(&mut self) {
self.analysis_host.apply_change(AnalysisChange::new());
}
pub fn snapshot(&self) -> ServerWorld {
ServerWorld {
workspaces: Arc::clone(&self.workspaces),