Skip to content

Commit

Permalink
reduce memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Feb 23, 2024
1 parent f520111 commit b193529
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
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

0 comments on commit b193529

Please sign in to comment.