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: performance overhaul #26114
Draft
GalacticHypernova
wants to merge
165
commits into
nuxt:main
Choose a base branch
from
GalacticHypernova:patch-9
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
perf: performance overhaul #26114
Conversation
This file contains 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.
NOTE:
This is a continuation and a rework of the previous PR that had some unexplainable issues so I decided to rewrite it. I have opened this to rework it more carefully and take care of all the edge cases and random errors. (For more info, please refer to #25771)
NOTE 2:
The 70 docs commits are due to me forgetting to flush the original patch-9 branch when I was done with that one. I usually start these PR's remotely, which means I don't get to name them something unique, and I just got onto the github app to try and re-run the failed tests, which still had the old patch-9 commits. That's my bad. I used the origin's files in every conflict so it ended up just not changing anything (as can be seen in the files changed).
π Linked issue
Related: #25771
β Type of change
π Description
This is a PR that aims to improve both build time and runtime performance to the max by refactoring everything that comes to mind with performance best practices, some of which include smarter and fewer object/array iterations, reduced indexes, smarter variable usage for constant values, and more.
Some key improvements in this PR:
Refactors of known costly javascript methods:
In some places throughout the app, there are operations that rely on certain javascript methods that are known to be more expensive at certain conditions than manual implementation
(similar to
endsWith
in perf(vite): rework endsWith to direct indexΒ #24746and
startsWith
in perf(kit, schema, nuxt): rework startsWith to direct indexΒ #24744).One key change under this category is the usage of
Array.prototype.includes
.Array.prototype.includes
appears to be slower when checking for existence of a certain input between at the very least 2 elements than directly checking each element with strict equality (like when dealing with strings).After thorough benchmarking, both browser and node, direct comparisons showed marginally better performance, benchmarks attached below in that same order with the following benchmark:
Browser:
Node:
Reduced and reworked iterations
Originally the main change in this PR, many parts in nuxt involve some sort of array/object manipulations, and in some places they are either repeated, redundant, or simply costly in terms of performance. The main examples of such cases are the small side PR's I have submitted like perf(kit): avoid duplicate
join
operationΒ #24717, perf(nuxt): avoid duplicate iterations over layersΒ #24730, and numerous others. I couldn't get all of it at the same time so I have decided to group the rest here, and also handle the iteration logic as opposed to mere count.Reduced indexes:
Some places in nuxt include working with indexes, like the
length
property of array/strings. While that alone isn't expensive, it still makes that repeated index, which especially with bigger inputs (like in HTML parsing or AST traversal) will gradually cost more and more microseconds, and might eventually become slightly noticeable in page performance.Early returns
Similar to perf: don't manipulate an empty valueΒ #25647, there are some places where some iterations are made on potentially empty values, which increase the overhead and therefore decrease performance. This PR adds guards to ensure there won't be iterations over an empty value.
π Checklist