Skip to content

Make line_col faster.#229

Merged
bors[bot] merged 2 commits intosoftdevteam:masterfrom
ltratt:faster_line_col
Jan 8, 2021
Merged

Make line_col faster.#229
bors[bot] merged 2 commits intosoftdevteam:masterfrom
ltratt:faster_line_col

Conversation

@ltratt
Copy link
Copy Markdown
Member

@ltratt ltratt commented Jan 7, 2021

line_col was previously a linear search that called another function that does a linear search. This PR changes the first linear search into a binary search (b62cab2) and removes the second linear search entirely (2d61edb).

This speeds up the easy bits of line_col significantly, moving us from O(4n + x) into O(log_n + x) where n is the number of lines in the file and x is whatever the cost to calculate the character offset from a line containing a string of bytes. Alas, this second thing is probably impossible to speed-up given that we're dealing with UTF-8. Still, this PR does at least address the most obviously egregious inefficiencies in line_col and it does so while decreasing the lines of code (allowing for the fact that I've added three lines of comments)!

@ptersilie
Copy link
Copy Markdown
Member

bors r+

bors Bot added a commit that referenced this pull request Jan 8, 2021
229: Make line_col faster. r=ptersilie a=ltratt

`line_col` was previously a linear search that called another function that does a linear search. This PR changes the first linear search into a binary search (b62cab2) and removes the second linear search entirely (2d61edb).

This speeds up the easy bits of `line_col` significantly, moving us from `O(4n + x)` into `O(log_n + x)` where `n` is the number of lines in the file and `x` is whatever the cost to calculate the character offset from a line containing a string of bytes. Alas, this second thing is probably impossible to speed-up given that we're dealing with UTF-8. Still, this PR does at least address the most obviously egregious inefficiencies in `line_col` and it does so while decreasing the lines of code (allowing for the fact that I've added three lines of comments)!

Co-authored-by: Laurence Tratt <laurie@tratt.net>
@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Jan 8, 2021

Build failed:

@ltratt
Copy link
Copy Markdown
Member Author

ltratt commented Jan 8, 2021

96f2ebc should fix the bors error and will need squashing.

bors try

bors Bot added a commit that referenced this pull request Jan 8, 2021
@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Jan 8, 2021

try

Build succeeded:

@ptersilie
Copy link
Copy Markdown
Member

Please squash.

This reduces the amount of work `line_col` has to do, as we can infer the same
information that `span_lines_str` has to calculate from scratch.
@ltratt
Copy link
Copy Markdown
Member Author

ltratt commented Jan 8, 2021

Squashed.

@ptersilie
Copy link
Copy Markdown
Member

bors r+

@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Jan 8, 2021

Build succeeded:

@bors bors Bot merged commit e3bf52d into softdevteam:master Jan 8, 2021
@ltratt ltratt deleted the faster_line_col branch October 2, 2021 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants