Why are std::fstreams so slow?

前端 未结 5 849
不思量自难忘°
不思量自难忘° 2021-01-30 20:49

I was working on a simple parser and when profiling I observed the bottleneck is in... file read! I extracted very simple test to compare the performance of fstreams

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 21:25

    A side note for whom interests. The main keywords are Windows 2016 server /CloseHandle.

    In our app we discovered a NASTY bug on win2016 server.

    Our std code under EVERY windows version takes: (ms)

    time CreateFile/SetFilePointer 1 WriteFile 0 CloseHandle 0

    on windows 2016 we got:

    time CreateFile/SetFilePointer 1 WriteFile 0 CloseHandle 275

    And times grows with dimension of file, that is ABSURD.

    After a LOT of investigations (we first found "CloseHandle" is the culprit...) we discovered that under windows2016 MS attached an "hook" in close function that triggers "Windows Defender" to scan ALL the file and prevents returning until done. (in other words scanning is synchronous, that is PURE MADNESS).

    When we added exclusion in "Defender" for our file, all works fine. I think is a BAD design, no antivirus stops normal file active INSIDE program space to scan files. (MS can do it as they have the power to do so.)

提交回复
热议问题