Skip to content
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

Merged
merged 1 commit into from Oct 5, 2021
Merged

Optimization of string splitting #13812

merged 1 commit into from Oct 5, 2021

Conversation

shoonia
Copy link
Contributor

@shoonia shoonia commented Oct 4, 2021

Added a limit for split operation. It decreases the count of the new strings.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 4, 2021

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:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/49000/

@nicolo-ribaudo
Copy link
Member

Could you share some microbenchmarks that show how much this improves the performance of @babel/code-frame?

@nicolo-ribaudo nicolo-ribaudo added the PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories label Oct 4, 2021
@@ -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)
Copy link
Member

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?

Copy link
Contributor Author

@shoonia shoonia Oct 5, 2021

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.

@shoonia
Copy link
Contributor Author

shoonia commented Oct 4, 2021

Simple benchmark: https://www.measurethat.net/Benchmarks/Show/15167/0/stringsplit-with-limit-4

split without limit:    x 2,553,672 ops/sec ±1.01% (62 runs sampled)
split with limit:       x 3,371,414 ops/sec ±0.52% (64 runs sampled)

@nicolo-ribaudo
Copy link
Member

Thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit 42c9eda into babel:main Oct 5, 2021
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 5, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Performance 🏃‍♀️ A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants