-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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(kit, schema, nuxt): rework startsWith to direct index #24744
Conversation
|
Making this a draft too to make as many changes as possible. How many characters would you say would be a fair tradeoff between readability and performance? I don't mind simply adding clear comments above each change so that even newcomers would understand 10 character checks, and allow for maximal speed and efficiency. |
I do believe this is all of it, I had to test it very thoroughly, so far I have gotten reliable consistent results (in favor of this PR's method) with up to 2 characters. Of course, I will continue testing to see if this can be improved further. |
π Linked issue
β Type of change
π Description
JS's startWith is known to have a performance downgrade compared to traditional character checking (you can see more here how vite also substituted those). And indeed, the performance increase is very much noticeable (~20% increase in performance in single character checks and ~15% increase in performance from starting 2 characters, increasing further as more characters are introduced).
Benchmark results:
Now, I know this hurts readability a bit, which is why to make a reasonable tradeoff (if you guys would like to), it is possible to only substitue for single character and double character check, and keep the rest with startsWith. I am curious to hear your opinion on how many characters you would like to substitue (do note that
startsWith
with 10 characters would be many times slower than===
with 10 characters)π Checklist