Unverified Commit 1d2225ea authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: reduce memory usage (#62432)

### What?

Avoid cloning a bit

### Why?

less allocations and memory usage

### How?


Closes PACK-2584
parent e5d604f3
...@@ -139,6 +139,8 @@ async fn build_manifest( ...@@ -139,6 +139,8 @@ async fn build_manifest(
..Default::default() ..Default::default()
}; };
let key = format!("app{page_name}");
let actions_value = actions.await?; let actions_value = actions.await?;
let loader_id_value = loader_id.await?; let loader_id_value = loader_id.await?;
let mapping = match runtime { let mapping = match runtime {
...@@ -147,12 +149,12 @@ async fn build_manifest( ...@@ -147,12 +149,12 @@ async fn build_manifest(
}; };
for (hash_id, (layer, _name, _module)) in actions_value { for (hash_id, (layer, _name, _module)) in actions_value {
let entry = mapping.entry(hash_id.clone()).or_default(); let entry = mapping.entry(hash_id.as_str()).or_default();
entry.workers.insert( entry.workers.insert(
format!("app{page_name}"), &key,
ActionManifestWorkerEntry::String(loader_id_value.clone_value()), ActionManifestWorkerEntry::String(loader_id_value.as_str()),
); );
entry.layer.insert(format!("app{page_name}"), *layer); entry.layer.insert(&key, *layer);
} }
Ok(Vc::upcast(VirtualOutputAsset::new( Ok(Vc::upcast(VirtualOutputAsset::new(
...@@ -261,7 +263,7 @@ async fn get_referenced_modules( ...@@ -261,7 +263,7 @@ async fn get_referenced_modules(
) -> Result<impl Iterator<Item = (ActionLayer, Vc<Box<dyn Module>>)> + Send> { ) -> Result<impl Iterator<Item = (ActionLayer, Vc<Box<dyn Module>>)> + Send> {
primary_referenced_modules(module) primary_referenced_modules(module)
.await .await
.map(|modules| modules.clone_value().into_iter().map(move |m| (layer, m))) .map(|modules| modules.into_iter().map(move |&m| (layer, m)))
} }
/// Parses the Server Actions comment for all exported action function names. /// Parses the Server Actions comment for all exported action function names.
......
...@@ -177,28 +177,28 @@ pub struct LoadableManifest { ...@@ -177,28 +177,28 @@ pub struct LoadableManifest {
#[derive(Serialize, Default, Debug)] #[derive(Serialize, Default, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ServerReferenceManifest { pub struct ServerReferenceManifest<'a> {
/// A map from hashed action name to the runtime module we that exports it. /// A map from hashed action name to the runtime module we that exports it.
pub node: HashMap<String, ActionManifestEntry>, pub node: HashMap<&'a str, ActionManifestEntry<'a>>,
/// A map from hashed action name to the runtime module we that exports it. /// A map from hashed action name to the runtime module we that exports it.
pub edge: HashMap<String, ActionManifestEntry>, pub edge: HashMap<&'a str, ActionManifestEntry<'a>>,
} }
#[derive(Serialize, Default, Debug)] #[derive(Serialize, Default, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct ActionManifestEntry { pub struct ActionManifestEntry<'a> {
/// A mapping from the page that uses the server action to the runtime /// A mapping from the page that uses the server action to the runtime
/// module that exports it. /// module that exports it.
pub workers: HashMap<String, ActionManifestWorkerEntry>, pub workers: HashMap<&'a str, ActionManifestWorkerEntry<'a>>,
pub layer: HashMap<String, ActionLayer>, pub layer: HashMap<&'a str, ActionLayer>,
} }
#[derive(Serialize, Debug)] #[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
#[serde(untagged)] #[serde(untagged)]
pub enum ActionManifestWorkerEntry { pub enum ActionManifestWorkerEntry<'a> {
String(String), String(&'a str),
Number(f64), Number(f64),
} }
......
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