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(nuxt): don't dedupe fewer than two middleware/plugins #24718
Conversation
Run & review this pull request in StackBlitz Codeflow. |
I will look into optimizing the entire Set handling as well (perhaps rework it to a Map?), but from my current benchmarks the results are inconclusive and quite mixed (potentially because of it running online, which I will do some offline testing soon) so I have not added that part yet. |
Update: the new update (the single file early return) yields even faster results, I will soon post new benchmark results |
Nuxt itself will always add more than 2 plugins, which means the additional check is likely to increase the time required when resolving plugins. (Though I don't see the harm in adding this check as it might be relevant for middleware - Nuxt only adds one by default.) |
Well, the check is O(1), so it doesn't add time at all compared to the time it saves (as you mentioned with the middleware). I'm not sure about the usability of that function in modules and the likes, but could people use it in their own modules or to register their own middleware/plugins? |
It adds time (technically) because it will always be This function is only used to deduplicate plugins and middleware in this file. |
π Linked issue
β Type of change
π Description
This PR returns early in the
uniqueBy
function that is used to gather all the unique plugins/middleware/etc whenever the input array is empty (which isn't unrealistic, if someone doesn't use any plugins for example) or contains a single file (guaranteed to be unique), avoiding all the computation afterwards and increasing performance in both cases by ~66.67%.With the following benchmark I have gotten the following results:
π Checklist