Skip to content

Commit

Permalink
perf(resolver): remove extra large fields from raw package json
Browse files Browse the repository at this point in the history
closes #2
  • Loading branch information
Boshen committed Dec 14, 2023
1 parent 05279e9 commit 349f5a9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/package_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ impl PackageJson {

package_json.path = path;
package_json.realpath = realpath;

// Remove large fields that useless for pragmatic use, see [raw_json] API
if let Some(package_json_value) = package_json_value.as_object_mut() {
package_json_value.remove("description");
package_json_value.remove("keywords");
package_json_value.remove("scripts");
package_json_value.remove("dependencies");
package_json_value.remove("devDependencies");
package_json_value.remove("peerDependencies");
package_json_value.remove("optionalDependencies");
}

package_json.raw_json = Arc::new(package_json_value);
Ok(package_json)
}
Expand All @@ -201,7 +213,15 @@ impl PackageJson {
Some(value)
}

/// Raw json of `package.json`
/// Raw serde json value of `package.json`.
///
/// This is currently used in Rspack for:
/// * getting the `sideEffects` field
/// * query in <https://www.rspack.dev/config/module.html#ruledescriptiondata> - search on GitHub indicates query on the `type` field.
///
/// To reduce overall memory consumption, large fields that useless for pragmatic use are removed.
/// They are: `description`, `keywords`, `scripts`,
/// `dependencies` and `devDependencies`, `peerDependencies`, `optionalDependencies`.
pub fn raw_json(&self) -> &serde_json::Value {
self.raw_json.as_ref()
}
Expand Down

0 comments on commit 349f5a9

Please sign in to comment.