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
Optimization of string splitting #13812
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit c1f6666:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/49000/ |
Could you share some microbenchmarks that show how much this improves the performance of |
@@ -147,7 +147,7 @@ export function codeFrameColumns( | |||
const highlightedLines = highlighted ? highlight(rawLines, opts) : rawLines; | |||
|
|||
let frame = highlightedLines | |||
.split(NEWLINE) | |||
.split(NEWLINE, end) | |||
.slice(start, end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need , end
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's limit for .split()
. If we have, supposed, 100 lines and we need to grab from 30 to 34 lines. We know the end line it's a 34, so the .split()
creates the first 34 lines and stops.
Simple benchmark: https://www.measurethat.net/Benchmarks/Show/15167/0/stringsplit-with-limit-4
|
Thanks! |
Added a limit for split operation. It decreases the count of the new strings.