Unverified Commit c450cd83 authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

[turbopack] Remove a vec clone from `primary_chunkable_referenced_modules` (#81206)

Remove a vec clone when resolving module primary references.  Since it is stored in a turbotask we can just pass around a ReadRef to the Vec.

By avoiding the copy we make the `ModulesWithRefData` type a little smaller and should speed up the loop, the cost is some additional indirection when iterating, however all callers only iterate once so this ends up as a win in all cases.
parent b4698a74
...@@ -3,7 +3,7 @@ use std::collections::HashSet; ...@@ -3,7 +3,7 @@ use std::collections::HashSet;
use anyhow::Result; use anyhow::Result;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ use turbo_tasks::{
FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString, Vc, FxIndexSet, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, ValueToString, Vc,
graph::{AdjacencyMap, GraphTraversal}, graph::{AdjacencyMap, GraphTraversal},
}; };
...@@ -285,9 +285,8 @@ pub async fn primary_referenced_modules(module: Vc<Box<dyn Module>>) -> Result<V ...@@ -285,9 +285,8 @@ pub async fn primary_referenced_modules(module: Vc<Box<dyn Module>>) -> Result<V
Ok(Vc::cell(modules)) Ok(Vc::cell(modules))
} }
type ModulesVec = Vec<ResolvedVc<Box<dyn Module>>>;
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
pub struct ModulesWithRefData(Vec<(ChunkingType, ExportUsage, ModulesVec)>); pub struct ModulesWithRefData(Vec<(ChunkingType, ExportUsage, ReadRef<Modules>)>);
/// Aggregates all primary [Module]s referenced by an [Module] via [ChunkableModuleReference]s. /// Aggregates all primary [Module]s referenced by an [Module] via [ChunkableModuleReference]s.
/// This does not include transitively referenced [Module]s, only includes /// This does not include transitively referenced [Module]s, only includes
...@@ -296,7 +295,7 @@ pub struct ModulesWithRefData(Vec<(ChunkingType, ExportUsage, ModulesVec)>); ...@@ -296,7 +295,7 @@ pub struct ModulesWithRefData(Vec<(ChunkingType, ExportUsage, ModulesVec)>);
/// [Module]: crate::module::Module /// [Module]: crate::module::Module
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn primary_chunkable_referenced_modules( pub async fn primary_chunkable_referenced_modules(
module: Vc<Box<dyn Module>>, module: ResolvedVc<Box<dyn Module>>,
include_traced: bool, include_traced: bool,
) -> Result<Vc<ModulesWithRefData>> { ) -> Result<Vc<ModulesWithRefData>> {
let modules = module let modules = module
...@@ -317,7 +316,6 @@ pub async fn primary_chunkable_referenced_modules( ...@@ -317,7 +316,6 @@ pub async fn primary_chunkable_referenced_modules(
.resolve() .resolve()
.await? .await?
.primary_modules() .primary_modules()
.owned()
.await?; .await?;
let export = reference.export_usage().owned().await?; let export = reference.export_usage().owned().await?;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment