Skip to content

Commit

Permalink
reduce number of allocations
Browse files Browse the repository at this point in the history
VecDeque::new always allocates 7 elements
  • Loading branch information
sokra committed Nov 24, 2022
1 parent beebae2 commit 92d1031
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/turbo-tasks-memory/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ impl Task {
backend: &MemoryBackend,
turbo_tasks: &dyn TurboTasksBackendApi,
) {
let mut queue = VecDeque::new();
let mut queue = VecDeque::with_capacity(0);
self.add_to_scope_internal_shallow(
id,
is_optimization_scope,
Expand Down Expand Up @@ -913,7 +913,7 @@ impl Task {
backend: &MemoryBackend,
turbo_tasks: &dyn TurboTasksBackendApi,
) {
let mut queue = VecDeque::new();
let mut queue = VecDeque::with_capacity(0);
self.remove_from_scope_internal_shallow(id, backend, turbo_tasks, &mut queue);
run_remove_from_scope_queue(queue, id, backend, turbo_tasks);
}
Expand Down Expand Up @@ -1523,8 +1523,8 @@ pub fn run_add_to_scope_queue(
&mut queue,
);
});
if queue.len() > SPLIT_OFF_QUEUE_AT {
let split_off_queue = queue.split_off(SPLIT_OFF_QUEUE_AT);
while queue.len() > SPLIT_OFF_QUEUE_AT {
let split_off_queue = queue.split_off(queue.len() - SPLIT_OFF_QUEUE_AT);
turbo_tasks.schedule_backend_foreground_job(backend.create_backend_job(
Job::AddToScopeQueue(split_off_queue, id, is_optimization_scope),
));
Expand All @@ -1543,8 +1543,8 @@ pub fn run_remove_from_scope_queue(
backend.with_task(child, |child| {
child.remove_from_scope_internal_shallow(id, backend, turbo_tasks, &mut queue);
});
if queue.len() > SPLIT_OFF_QUEUE_AT {
let split_off_queue = queue.split_off(SPLIT_OFF_QUEUE_AT);
while queue.len() > SPLIT_OFF_QUEUE_AT {
let split_off_queue = queue.split_off(queue.len() - SPLIT_OFF_QUEUE_AT);

turbo_tasks.schedule_backend_foreground_job(
backend.create_backend_job(Job::RemoveFromScopeQueue(split_off_queue, id)),
Expand Down

0 comments on commit 92d1031

Please sign in to comment.