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(object-hash): faster extract object type from toString #31

Merged
merged 1 commit into from
Apr 22, 2023

Conversation

H4ad
Copy link
Contributor

@H4ad H4ad commented Apr 22, 2023

Inspired by puleos/object-hash#122

perf: faster extract object type from toString

Using slice again instead of Regex.

'oldRegex x 12,546,910 ops/sec ±2.65% (81 runs sampled)',
'slice x 1,135,283,250 ops/sec ±0.30% (97 runs sampled)'

Benchmark: bench-object-type.js

objType = "unknown:[" + objString + "]";
} else {
// '[object '.length === 8
objType = objString.slice(8, objectLength - 1);
Copy link
Member

Choose a reason for hiding this comment

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

This can introduce a regression of string is not ending with ] (which regex was testing before)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I see and test, is impossible to see a string not ending with ], so it's not a problem.

@codecov
Copy link

codecov bot commented Apr 22, 2023

Codecov Report

Merging #31 (32b6ae9) into main (23431de) will increase coverage by 0.14%.
The diff coverage is 91.66%.

@@            Coverage Diff             @@
##             main      #31      +/-   ##
==========================================
+ Coverage   80.37%   80.51%   +0.14%     
==========================================
  Files           8        8              
  Lines         968      975       +7     
  Branches      125      126       +1     
==========================================
+ Hits          778      785       +7     
  Misses        190      190              
Impacted Files Coverage Δ
src/object-hash.ts 63.77% <91.66%> (+0.65%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@pi0 pi0 merged commit 8b6711b into unjs:main Apr 22, 2023
@H4ad H4ad deleted the perf/faster-extract-object-type branch April 22, 2023 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants