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

perf(rspack_core): replace HASH_PLACEHOLDER_REGEX with simple string parsing #7907

Conversation

shulaoda
Copy link
Collaborator

@shulaoda shulaoda commented Sep 15, 2024

Summary

Related to rolldown/rolldown#1496

I plan to convert all the regular expressions into string lookup, because these regular expressions are very simple and do not require regex.

pub static FILE_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\[file\]").expect("Should generate regex"));
pub static BASE_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\[base\]").expect("Should generate regex"));
pub static NAME_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\[name\]").expect("Should generate regex"));
pub static PATH_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\[path\]").expect("Should generate regex"));
pub static EXT_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\[ext\]").expect("Should generate regex"));
pub static QUERY_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\[query\]").expect("Should generate regex"));
pub static FRAGMENT_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\[fragment\]").expect("Should generate regex"));
pub static ID_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\[id\]").expect("Should generate regex"));
pub static RUNTIME_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\[runtime\]").expect("Should generate regex"));
pub static URL_PLACEHOLDER: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"\[url\]").expect("Should generate regex"));

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions github-actions bot added the release: performance release: performance related release(mr only) label Sep 15, 2024
Copy link

netlify bot commented Sep 15, 2024

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit a06f078
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/670640b86100ef0008c9cd22

@shulaoda shulaoda marked this pull request as draft September 15, 2024 14:22
@shulaoda shulaoda marked this pull request as ready for review September 16, 2024 05:51
@chenjiahan
Copy link
Member

@shulaoda can you resolve the conflicts? ❤️

@shulaoda shulaoda marked this pull request as draft October 8, 2024 13:05
@shulaoda shulaoda force-pushed the perf/hash-placeholder-to-simple-string-parse branch from f5a5e21 to a429391 Compare October 8, 2024 23:06
@shulaoda shulaoda marked this pull request as ready for review October 8, 2024 23:23
@shulaoda shulaoda force-pushed the perf/hash-placeholder-to-simple-string-parse branch from 5bd31c7 to a06f078 Compare October 9, 2024 08:37
@h-a-n-a
Copy link
Collaborator

h-a-n-a commented Oct 10, 2024

Wasn't the issue in the description had been resolved? I think this is necessary.

I'm not sure if the hash pattern appears only once. If there are cases where the pattern appears multiple times, such as [hash]-[hash:6].js, I need to optimize further.

let result = replace_all_hash_pattern("hello-[hash]-[hash:5].js", "[hash]", |n| {
    &"abcdefgh"[..n.unwrap_or(8)]
  });
 assert_eq!(result, Some("hello-abcdefgh-abcde.js".to_string()));

@shulaoda
Copy link
Collaborator Author

shulaoda commented Oct 10, 2024

Wasn't the issue in the description had been resolved? I think this is necessary.

Sorry. This is a PR from a long time ago, and I fixed the issues in the description later. I have revised the description.

@h-a-n-a h-a-n-a merged commit 233e811 into web-infra-dev:main Oct 14, 2024
37 checks passed
@shulaoda shulaoda deleted the perf/hash-placeholder-to-simple-string-parse branch October 14, 2024 04:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: performance release: performance related release(mr only)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants