Title: util: add fast path to stripVTControlCharacters by privatenumber · Pull Request #61833 · nodejs/node · GitHub
Open Graph Title: util: add fast path to stripVTControlCharacters by privatenumber · Pull Request #61833 · nodejs/node
X Title: util: add fast path to stripVTControlCharacters by privatenumber · Pull Request #61833 · nodejs/node
Description: Problem stripVTControlCharacters always runs a regex replacement, even when the input contains no ANSI escape codes. This is the common case — most strings passed through are already plain text (e.g. checking/sanitizing user input, processing log lines that are mostly text). Changes Adds a StringPrototypeIndexOf guard for ESC (\u001B) and CSI (\u009B) before the regex. Since all ANSI escape sequences start with one of these introducers, their absence means no ANSI codes exist and we can return the string immediately — skipping regex execution. Based on the same optimization proposed in chalk/strip-ansi#54. Also adds a benchmark and test coverage for the fast path, 7-bit ESC sequences, and 8-bit CSI sequences. Benchmarks Node.js benchmark results using benchmark/compare.js (30 runs, two separate builds): confidence improvement accuracy (*) (**) (***) util/strip-vt-control-characters.js input='noAnsi-short' n=1000000 *** 93.43 % ±3.42% ±4.56% ±5.94% util/strip-vt-control-characters.js input='noAnsi-long' n=1000000 *** 591.26 % ±9.71% ±12.97% ±16.97% util/strip-vt-control-characters.js input='ansi-short' n=1000000 -0.32 % ±1.39% ±1.85% ±2.41% util/strip-vt-control-characters.js input='ansi-long' n=1000000 1.74 % ±2.55% ±3.39% ±4.42% ~1.93x faster for short non-ANSI strings, ~6.91x for long non-ANSI strings. Negligible impact on ANSI input.
Open Graph Description: Problem stripVTControlCharacters always runs a regex replacement, even when the input contains no ANSI escape codes. This is the common case — most strings passed through are already plain text (e....
X Description: Problem stripVTControlCharacters always runs a regex replacement, even when the input contains no ANSI escape codes. This is the common case — most strings passed through are already plain text (e....
Opengraph URL: https://github.com/nodejs/node/pull/61833
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:73854cc7-b1fb-0454-0a2d-ed9fd2f8fd65 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 80AC:3F81E9:D08A5F:11D1BDF:6A4C58D1 |
| html-safe-nonce | 122ca578e68bfd7cfca81e31d454f214df97dc220011263633b862136a77bf75 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEFDOjNGODFFOTpEMDhBNUY6MTFEMUJERjo2QTRDNThEMSIsInZpc2l0b3JfaWQiOiIyNjA2NzIwMDI1NzI2MDQ4NDY1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8a276df34809851d2229298176d0ab6ee705692b51b291729836052ff12803b2 |
| hovercard-subject-tag | pull_request:3285855585 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/nodejs/node/pull/61833/files |
| twitter:image | https://avatars.githubusercontent.com/u/1075694?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1075694?s=400&v=4 |
| og:image:alt | Problem stripVTControlCharacters always runs a regex replacement, even when the input contains no ANSI escape codes. This is the common case — most strings passed through are already plain text (e.... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 14099438da5379150f15a2892474c7c7e6c0e55e |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width