Repository navigation
perf(isEmail, isFQDN, normalizeEmail): up to 2x faster by skipping the default-options copy - #2932
Open
deadstrobe5 wants to merge 1 commit into
Open
deadstrobe5 wants to merge 1 commit into
deadstrobe5 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2932 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2599 2599
Branches 658 660 +2
=========================================
Hits 2599 2599 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When called without
options,isEmail,isFQDNandnormalizeEmailranmerge(undefined, defaults), which allocates a new object and copies every default into it on each call. None of these functions mutateoptionsor pass it on to code that does (isEmailbuilds a fresh object for itsisFQDNcall), so they can read the module-level defaults directly. Calls that pass options still go throughmergeunchanged, and any falsyoptionsvalue previously produced exactly a copy of the defaults, so results are the same.Benchmark (Node 26, Apple M5, A/B interleaved in one process, 20 rounds × 100 ms, median ratio; an A/A control gave 1.00 with ±2–4% noise):
isEmailisFQDNnormalizeEmailisURLis unchanged on purpose: it passes its own options object toisFQDN, so it keeps the current path.A differential test of ~186,000 inputs and option combinations (calls with and without options interleaved in one process) against the previous build found no differing results.
npm testpasses (323 tests, 100% coverage on the changed files) and eslint is clean.Checklist