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

Optimize max_line_len #1109

Merged
merged 1 commit into from Nov 14, 2021
Merged

Commits on Nov 14, 2021

  1. Optimize max_line_len

    The old max_line_len code fell into a surprising slowdown where repeatedly inserting chars in the middle of a string falls into O(n^2) behavior. Surprising because V8 already implements advanced data structures for string slicing and joining (`SlicedString` and `ConsString`). It seems like this should be easily handled by the two.
    
    Anyways, we avoid this by slowing building a committed string (which is unlikely to be changed). Whenever we insert, we commit the left hand side, and can avoid slicing it in the future.
    
    In testing a 5mb file (done by repeating a program several times), I dropped the simple parse+output case from 5min to 5sec.
    jridgewell committed Nov 14, 2021
    Copy the full SHA
    8f7706d View commit details
    Browse the repository at this point in the history