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

feat: parseIdentifier fast path for requests without \0 #444

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

dmichon-msft
Copy link
Contributor

Adds a fast path to parseIdentifier that avoids the overhead of regex processing when the input does not contain a null character. Improves performance of parseIdentifier by ~75% for typical usage on NodeJS 18.19.1.

Before:
image

After:
image

Adds additional unit tests to parseIdentifier for NULL-escaped strings.


/**
* @param {string} identifier identifier
* @returns {[string, string, string]|null} parsed identifier
*/
function parseIdentifier(identifier) {
if (!identifier) {
return null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly this should be ["","",""]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that in practice it doesn't matter to callers.

@TheLarkInn TheLarkInn requested a review from Copilot January 16, 2025 21:30

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.41%. Comparing base (35b67ce) to head (40a4050).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #444      +/-   ##
==========================================
- Coverage   92.50%   92.41%   -0.10%     
==========================================
  Files          44       44              
  Lines        2135     2149      +14     
  Branches      657      662       +5     
==========================================
+ Hits         1975     1986      +11     
- Misses        131      132       +1     
- Partials       29       31       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexander-akait alexander-akait merged commit 7408b73 into webpack:main Feb 4, 2025
27 of 28 checks passed
@alexander-akait
Copy link
Member

Thank you

@dmichon-msft dmichon-msft deleted the parse-identifier-perf branch February 4, 2025 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants