Skip to content

Commit

Permalink
Merge 9a04ec3 into 0723170
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra authored Dec 2, 2022
2 parents 0723170 + 9a04ec3 commit 015b68b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
8 changes: 8 additions & 0 deletions crates/auto-hash-map/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ impl<K: Eq + Hash, V, H: BuildHasher + Default> AutoMap<K, V, H> {
},
}
}

/// see [HashMap::shrink_to_fit](https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.shrink_to_fit)
pub fn shrink_to_fit(&mut self) {
match self {
AutoMap::List(list) => list.shrink_to_fit(),
AutoMap::Map(map) => map.shrink_to_fit(),
}
}
}

impl<K: Eq + Hash, V, H: BuildHasher> AutoMap<K, V, H> {
Expand Down
5 changes: 5 additions & 0 deletions crates/auto-hash-map/src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ impl<K: Hash + Eq, H: BuildHasher + Default> AutoSet<K, H> {
self.map.extend(iter.into_iter().map(|item| (item, ())))
}

/// see [HashSet::shrink_to_fit](https://doc.rust-lang.org/std/collections/hash_set/struct.HashSet.html#method.shrink_to_fit)
pub fn shrink_to_fit(&mut self) {
self.map.shrink_to_fit();
}

/// see [HashSet::contains](https://doc.rust-lang.org/std/collections/hash_set/struct.HashSet.html#method.contains)
pub fn contains(&self, key: &K) -> bool {
self.map.contains_key(key)
Expand Down
7 changes: 4 additions & 3 deletions crates/turbo-tasks-memory/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,10 @@ impl Task {
match state.state_type {
InProgress { ref mut event } => {
let event = event.take();
state.state_type = Done {
dependencies: take(&mut dependencies),
};
let mut dependencies = take(&mut dependencies);
// This will stay here for longer, so make sure to not consume too much memory
dependencies.shrink_to_fit();
state.state_type = Done { dependencies };
for scope in state.scopes.iter() {
backend.with_scope(scope, |scope| {
scope.decrement_unfinished_tasks(backend);
Expand Down
9 changes: 6 additions & 3 deletions crates/turbo-tasks/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ impl<B: Backend> TurboTasks<B> {

/// Call a native function with arguments.
/// All inputs must be resolved.
pub(crate) fn native_call(&self, func: FunctionId, inputs: Vec<TaskInput>) -> RawVc {
pub(crate) fn native_call(&self, func: FunctionId, mut inputs: Vec<TaskInput>) -> RawVc {
inputs.shrink_to_fit();
RawVc::TaskOutput(self.backend.get_or_create_persistent_task(
PersistentTaskType::Native(func, inputs),
current_task("turbo_function calls"),
Expand All @@ -327,10 +328,11 @@ impl<B: Backend> TurboTasks<B> {

/// Calls a native function with arguments. Resolves arguments when needed
/// with a wrapper [Task].
pub fn dynamic_call(&self, func: FunctionId, inputs: Vec<TaskInput>) -> RawVc {
pub fn dynamic_call(&self, func: FunctionId, mut inputs: Vec<TaskInput>) -> RawVc {
if inputs.iter().all(|i| i.is_resolved() && !i.is_nothing()) {
self.native_call(func, inputs)
} else {
inputs.shrink_to_fit();
RawVc::TaskOutput(self.backend.get_or_create_persistent_task(
PersistentTaskType::ResolveNative(func, inputs),
current_task("turbo_function calls"),
Expand All @@ -345,8 +347,9 @@ impl<B: Backend> TurboTasks<B> {
&self,
trait_type: TraitTypeId,
trait_fn_name: Cow<'static, str>,
inputs: Vec<TaskInput>,
mut inputs: Vec<TaskInput>,
) -> RawVc {
inputs.shrink_to_fit();
RawVc::TaskOutput(self.backend.get_or_create_persistent_task(
PersistentTaskType::ResolveTrait(trait_type, trait_fn_name, inputs),
current_task("turbo_function calls"),
Expand Down

0 comments on commit 015b68b

Please sign in to comment.