-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
improve performance (+99.5% throughput) #37
Conversation
Second change: Use a string search instead of RegExp to match ansi codesResult:
|
Third change: Don't spread the string into an array, loop through codepoints directlyResult:
|
4th change: Avoid converting ansi codes to number for end code lookupResult:
|
5th change: Don't use string.split to access first char before first ";", use indexOf and sliceResult:
|
This comment was marked as outdated.
This comment was marked as outdated.
test.js
Outdated
t.is(JSON.stringify(sliceAnsi('\u001B[31m' + output, 0, 4)), JSON.stringify(`\u001B[31m${chalk.black.bgYellow(' RUN')}`)); | ||
t.is(JSON.stringify(sliceAnsi('\u001B[31m' + output, 0, 4)), JSON.stringify(chalk.black.bgYellow(' RUN'))); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
test.js
Outdated
t.is(sliceAnsi('\u001B[1m\u001B[48;2;255;255;255m\u001B[38;2;255;0;0municorn\u001B[39m\u001B[49m\u001B[22m', 0, 3), '\u001B[1m\u001B[48;2;255;255;255m\u001B[38;2;255;0;0muni\u001B[22m\u001B[49m\u001B[39m'); | ||
t.is(sliceAnsi('\u001B[1m\u001B[48;2;255;255;255m\u001B[38;2;255;0;0municorn\u001B[39m\u001B[49m\u001B[22m', 0, 3), '\u001B[1m\u001B[48;2;255;255;255m\u001B[38;2;255;0;0muni\u001B[39m\u001B[49m\u001B[22m'); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
I think it'd be a lot easier for maintainers to review this PR and much more likely to merge your changes, if it was split up into much smaller PRs, focused on making each individual performance optimization. Right now it's hard to understand, because the whole library basically get rewritten, which would be a tough sell. |
Guess I can rip out the last two commits and put them up as an alternative. The others consecutively build on each other and sometimes undo what a previous one did, so splitting them into individual PRs doesn't make much sense to me. Edit: done |
As mentioned in vadimdemedes/ink#560, I'm having severe performance issues with this library. This PR is an attempt at making it faster.
I suggest reviewing the changes commit-by-commit, while reading the corresponding change description and benchmark. The last commit is a complete rewrite though.
I'm testing the impact of each change using the following benchmark:
The results are varying between tests a bit, but I'll try to post comparable benchmarks for each change.
First change: Use a simple for loop instead of calling
entries()
on the character arrayResult: