-
Notifications
You must be signed in to change notification settings - Fork 786
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
Remove massive string allocations #5940
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spurce is not normalized anymore. I'm not sure if that makes any difference, but in any case the property name "NormalizedSource" is now a lie
@forki Done thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this actually gives a green build then it looks like a massive win for saving allocations
@forki thanks you right now the LineEndPositions is according to the source and not the normalized source I think now it's ok |
[| | ||
let mutable pos = 0 | ||
yield pos | ||
for i in 0..source.Length-1 do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i and pos are always in sync right? So you can get rid of that mutable variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry thanks
ok so now I need to fix the tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good on my end, if everything is green I will merge.
It's green |
Thank you |
let c = source.[i] | ||
if c = '\r' && i + 1 < source.Length && source.[i+1] = '\n' then () | ||
elif c = '\r' then yield i + 1 | ||
if c = '\n' then yield i + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not this be an elif
? (It does not change the semantics but improves clarity.) @AviAvni
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine. alter native would be to pattern match on c
yield 0 | ||
for i in 0..source.Length-1 do | ||
let c = source.[i] | ||
if c = '\r' && i + 1 < source.Length && source.[i+1] = '\n' then () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style/readbility comment: looping through 1..source.Length
instead of 0..source.Length-1
would make more sense here, since we already processed the 0th byte with the yield 0
above the loop. This would also avoid the i+1
in four places:
[|
yield 0
for i in 1..source.Length do
let c = source.[i-1]
if c = '\r' && i < source.Length && source.[i] = '\n' then ()
elif c = '\r' then yield i
elif c = '\n' then yield i
yield source.Length
|]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think we should avoid duplicates as well.
{ NormalizedSource = source | ||
LineEndPositions = positions }) | ||
[| | ||
yield 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|> Seq.toArray | ||
{ NormalizedSource = source | ||
LineEndPositions = positions }) | ||
[| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Seq.pairwise
might be more elegant here, rahter than indexing in arrays. (Though I'm not sure if perf would be better or worse taking into account possible compiler optimization and CPU caching).
@@ -433,8 +433,7 @@ let _ = printf " %*a" 3 (fun _ _ -> ()) 2 | |||
typeCheckResults.GetFormatSpecifierLocationsAndArity() | |||
|> Array.map (fun (range,numArgs) -> range.StartLine, range.StartColumn, range.EndLine, range.EndColumn, numArgs) | |||
|> shouldEqual | |||
[|(2, 45, 2, 47, 1); (3, 23, 3, 25, 1); (4, 38, 4, 40, 1); (5, 27, 5, 29 | |||
, 1); | |||
[|(2, 45, 2, 47, 1); (3, 23, 3, 25, 1); (4, 38, 4, 40, 1); (5, 27, 5, 29, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just remove line break
See #5922