-
Notifications
You must be signed in to change notification settings - Fork 142
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: use direct array access instead of endsWIth
#387
Conversation
Thanks for the PR but I would appreciate sharing a benchmark diff. |
@pi0 sure thing! |
Script above is not related to unstoage. I understand that using index access vs |
I mean, I get your point, but I'd have to politely disagree with you on this one. It's not about banning a javascript feature. There are many builtin methods that are there because they have legitimate use cases, but it doesn't necessarily mean that every possible use case is an intended use case. I'm sure you've heard about As with any abstraction, it has its performance considerations, and there are simply cases when using it is not optimal. You might argue that abstractions make the code more readable, but in this scenario I doubt anyone would say that having a simple It's up to you whether to include this or not, but in such a critical component in the unjs ecosystem, in a part that is required to be as performant as possible, especially with certain drivers, I don't really see a reason not to include this, but I'll leave the decision up to you. |
|
Do you mean like an actual benchmark test with some benchmarking library? If we're talking about simply showing that it's indeed changing something I have provided a benchmark sample above. EndsWith doesn't discriminate between whether the code is for nuxt or unstorage, the slowdown happens all the time and can easily be observed based on the results that I have also attached, as that's how it was designed. However, if you'd like a full fledged benchmark, then we should already add benchmarks to everything, as nothing is currently benchmarked |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #387 +/- ##
==========================================
+ Coverage 65.05% 66.57% +1.52%
==========================================
Files 39 39
Lines 4055 4105 +50
Branches 487 511 +24
==========================================
+ Hits 2638 2733 +95
+ Misses 1408 1363 -45
Partials 9 9 ☔ View full report in Codecov by Sentry. |
Added bench scripts partially specific to this change via d84bcc6 You can try with Main:
This branch:
As you can see, the end-to-end difference is almost nothing. Not that it does not matter but hope you understand why micro-optimizations like this (even though, at micro-level are visible) do not essentially improve final performances that much but instead make code less consistent and less readable. (#386 perf improvement was not micro optimization to compare) I again appreciate your contribution but ask you kindly next times respect maintainer's decision and comments and try to collaborate. Working on the bench took over an hour of my early morning that desperately needed for other stuff. |
endsWIth
I appreciate the merge! I know these are micro optimizations, I never said it would be anything ground breaking, but micro optimizations will eventually add up, especially in performance-critical environments and in I/O bound work. I don't recall ever refusing to collaborate, I did leave the final decision to you, and I believe I have stated that, and I quote, "It's up to you whether to include this or not" and "I'll leave the decision up to you". I believe there was some miscommunication on the matter, which I would be more than willing to discuss in private if you're willing to. |
🔗 Linked issue
❓ Type of change
📚 Description
endsWith has a big performance problem when it comes to single or double character checking. We can convert it to index access for better performance.
📝 Checklist