-
Notifications
You must be signed in to change notification settings - Fork 300
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
[WIP] Fix #2869: Avoid unnecessary updates #2941
[WIP] Fix #2869: Avoid unnecessary updates #2941
Conversation
- Keep output in memory - Only write to file if there is a change or file is new Fix fable-compiler#2869
if count = 0 then return None | ||
else | ||
let res = | ||
if count = buffer.Length then buffer |
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.
As we are using a single buffer, if count = 0
we just return a reference to the buffer. But in the lines below:
let! nextBytes1 = readBytesAsync memoryStream
let! nextBytes2 = readBytesAsync fileStream
nextBytes1
is going to be same as nextBytes2
(if count is 0 in both cases), because readBytesAsync
returns the same array reference in both cases and the second readBytesAsync
will overwrite the buffer.
This is fantastic @hensou, thanks a lot for this! I've rewritten a bit the let IsMemoryStreamEqualToFileAsync() = async {
let areStreamsEqualAsync (stream1: IO.Stream) (stream2: IO.Stream) =
let buffer1 = Array.zeroCreate<byte> 1024
let buffer2 = Array.zeroCreate<byte> 1024
let rec areStreamsEqualAsync() = async {
let! count1 = stream1.AsyncRead(buffer1, 0, buffer1.Length)
let! count2 = stream2.AsyncRead(buffer2, 0, buffer2.Length)
match count1, count2 with
| 0, 0 -> return true
| count1, count2 when count1 = count2 && buffer1 = buffer2 ->
return! areStreamsEqualAsync()
| _ -> return false
}
areStreamsEqualAsync()
memoryStream.Seek(0, IO.SeekOrigin.Begin) |> ignore
use fileStream = IO.File.OpenRead(targetPath)
return! areStreamsEqualAsync memoryStream fileStream
} |
Awesome, I'm glad I could help.🙂 |
Fix #2869