Unverified Commit e1ad67d2 authored by lichu acuña's avatar lichu acuña Committed by GitHub

Changed module id map key from AssetIdent to RcStr (#69076)

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to understand the PR)
- When linking to a Slack thread, you might want to share details of the conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
parent 15c086c1
use std::collections::HashMap; use std::collections::HashMap;
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{ValueToString, Vc}; use turbo_tasks::{RcStr, ValueToString, Vc};
use turbo_tasks_hash::hash_xxh3_hash64; use turbo_tasks_hash::hash_xxh3_hash64;
use super::ModuleId; use super::ModuleId;
...@@ -31,11 +31,11 @@ impl ModuleIdStrategy for DevModuleIdStrategy { ...@@ -31,11 +31,11 @@ impl ModuleIdStrategy for DevModuleIdStrategy {
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct GlobalModuleIdStrategy { pub struct GlobalModuleIdStrategy {
module_id_map: HashMap<AssetIdent, Vc<ModuleId>>, module_id_map: HashMap<RcStr, Vc<ModuleId>>,
} }
impl GlobalModuleIdStrategy { impl GlobalModuleIdStrategy {
pub async fn new(module_id_map: HashMap<AssetIdent, Vc<ModuleId>>) -> Result<Vc<Self>> { pub async fn new(module_id_map: HashMap<RcStr, Vc<ModuleId>>) -> Result<Vc<Self>> {
Ok(GlobalModuleIdStrategy { module_id_map }.cell()) Ok(GlobalModuleIdStrategy { module_id_map }.cell())
} }
} }
...@@ -44,7 +44,8 @@ impl GlobalModuleIdStrategy { ...@@ -44,7 +44,8 @@ impl GlobalModuleIdStrategy {
impl ModuleIdStrategy for GlobalModuleIdStrategy { impl ModuleIdStrategy for GlobalModuleIdStrategy {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn get_module_id(self: Vc<Self>, ident: Vc<AssetIdent>) -> Result<Vc<ModuleId>> { async fn get_module_id(self: Vc<Self>, ident: Vc<AssetIdent>) -> Result<Vc<ModuleId>> {
if let Some(module_id) = self.await?.module_id_map.get(&ident.await?.clone_value()) { let ident_string = ident.to_string().await?.clone_value();
if let Some(module_id) = self.await?.module_id_map.get(&ident_string) {
// dbg!(format!("Hit {}", ident.to_string().await?)); // dbg!(format!("Hit {}", ident.to_string().await?));
return Ok(*module_id); return Ok(*module_id);
} }
......
...@@ -3,22 +3,21 @@ use std::collections::{HashMap, HashSet}; ...@@ -3,22 +3,21 @@ use std::collections::{HashMap, HashSet};
use anyhow::Result; use anyhow::Result;
use turbo_tasks::{ use turbo_tasks::{
graph::{AdjacencyMap, GraphTraversal}, graph::{AdjacencyMap, GraphTraversal},
ValueToString, Vc, RcStr, ValueToString, Vc,
}; };
use turbo_tasks_hash::hash_xxh3_hash64; use turbo_tasks_hash::hash_xxh3_hash64;
use turbopack_core::{ use turbopack_core::{
chunk::ModuleId, chunk::ModuleId,
ident::AssetIdent,
module::{Module, Modules}, module::{Module, Modules},
reference::primary_referenced_modules, reference::primary_referenced_modules,
}; };
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct PreprocessedChildrenIdents { pub struct PreprocessedChildrenIdents {
// module_id -> full hash // ident.to_string() -> full hash
// We save the full hash to avoid re-hashing in `merge_preprocessed_module_ids` // We save the full hash to avoid re-hashing in `merge_preprocessed_module_ids`
// if this endpoint did not change. // if this endpoint did not change.
modules_idents: HashMap<AssetIdent, u64>, modules_idents: HashMap<RcStr, u64>,
} }
pub async fn get_children_modules( pub async fn get_children_modules(
...@@ -50,8 +49,9 @@ pub async fn children_modules_idents( ...@@ -50,8 +49,9 @@ pub async fn children_modules_idents(
for module in children_modules_iter { for module in children_modules_iter {
let module_ident = module.ident(); let module_ident = module.ident();
let hash = hash_xxh3_hash64(module_ident.to_string().await?); let ident_str = module_ident.to_string().await?.clone_value();
modules_idents.insert(module_ident.await?.clone_value(), hash); let hash = hash_xxh3_hash64(&ident_str);
modules_idents.insert(ident_str, hash);
} }
Ok(PreprocessedChildrenIdents { modules_idents }.cell()) Ok(PreprocessedChildrenIdents { modules_idents }.cell())
...@@ -61,8 +61,8 @@ pub async fn children_modules_idents( ...@@ -61,8 +61,8 @@ pub async fn children_modules_idents(
// ids and another that generates the final, optimized module ids. Thoughts? // ids and another that generates the final, optimized module ids. Thoughts?
pub async fn merge_preprocessed_module_ids( pub async fn merge_preprocessed_module_ids(
prepared_module_ids: Vec<Vc<PreprocessedChildrenIdents>>, prepared_module_ids: Vec<Vc<PreprocessedChildrenIdents>>,
) -> Result<HashMap<AssetIdent, Vc<ModuleId>>> { ) -> Result<HashMap<RcStr, Vc<ModuleId>>> {
let mut module_id_map: HashMap<AssetIdent, Vc<ModuleId>> = HashMap::new(); let mut module_id_map: HashMap<RcStr, Vc<ModuleId>> = HashMap::new();
let mut used_ids: HashSet<u64> = HashSet::new(); let mut used_ids: HashSet<u64> = HashSet::new();
for prepared_module_ids in prepared_module_ids { for prepared_module_ids in prepared_module_ids {
...@@ -81,12 +81,12 @@ pub async fn merge_preprocessed_module_ids( ...@@ -81,12 +81,12 @@ pub async fn merge_preprocessed_module_ids(
} }
pub async fn process_module( pub async fn process_module(
module_ident: AssetIdent, ident_str: RcStr,
full_hash: u64, full_hash: u64,
id_map: &mut HashMap<AssetIdent, Vc<ModuleId>>, id_map: &mut HashMap<RcStr, Vc<ModuleId>>,
used_ids: &mut HashSet<u64>, used_ids: &mut HashSet<u64>,
) -> Result<()> { ) -> Result<()> {
if id_map.contains_key(&module_ident) { if id_map.contains_key(&ident_str) {
return Ok(()); return Ok(());
} }
...@@ -102,7 +102,7 @@ pub async fn process_module( ...@@ -102,7 +102,7 @@ pub async fn process_module(
let hashed_module_id = ModuleId::String(masked_hash.to_string().into()); let hashed_module_id = ModuleId::String(masked_hash.to_string().into());
id_map.insert(module_ident, hashed_module_id.cell()); id_map.insert(ident_str, hashed_module_id.cell());
used_ids.insert(masked_hash); used_ids.insert(masked_hash);
Ok(()) Ok(())
......
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