Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbopack: reduce memory usage #62432

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/next-swc/crates/next-api/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ async fn build_manifest(
..Default::default()
};

let key = format!("app{page_name}");

let actions_value = actions.await?;
let loader_id_value = loader_id.await?;
let mapping = match runtime {
Expand All @@ -147,12 +149,12 @@ async fn build_manifest(
};

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(
format!("app{page_name}"),
ActionManifestWorkerEntry::String(loader_id_value.clone_value()),
&key,
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(
Expand Down Expand Up @@ -261,7 +263,7 @@ async fn get_referenced_modules(
) -> Result<impl Iterator<Item = (ActionLayer, Vc<Box<dyn Module>>)> + Send> {
primary_referenced_modules(module)
.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.
Expand Down
16 changes: 8 additions & 8 deletions packages/next-swc/crates/next-core/src/next_manifests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,28 +177,28 @@ pub struct LoadableManifest {

#[derive(Serialize, Default, Debug)]
#[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.
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.
pub edge: HashMap<String, ActionManifestEntry>,
pub edge: HashMap<&'a str, ActionManifestEntry<'a>>,
}

#[derive(Serialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ActionManifestEntry {
pub struct ActionManifestEntry<'a> {
/// A mapping from the page that uses the server action to the runtime
/// 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)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
pub enum ActionManifestWorkerEntry {
String(String),
pub enum ActionManifestWorkerEntry<'a> {
String(&'a str),
Number(f64),
}

Expand Down