Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Ensure that LoadSequentialFile() actually read the whole file #5831
Ensure that LoadSequentialFile() actually read the whole file #5831
Changes from 5 commits
6810799
5a5f99c
469705b
c8fabb2
5083ca2
efc6f47
d57e0ab
4782c7d
2685ce6
29708e9
7bb99c6
4faae5b
c4b7ffa
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
@trivialfis Previously, we called
read()
only once. For a file containing 2896075944 bytes (2.69 GB),read()
only reads 2147479552 bytes (1.99 GB), and the variables would be set as follows:This PR ensures that
bytes_read
would be identical tof_size_bytes
, by callingread()
multiple times in awhile
loop.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.
@trivialfis Take a look at this while loop. This is a commonly used construct in UNIX programs.
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.
Note: According to the MSDN documentation,
ftell()
on Windows does not yield the correct byte offset when the file was opened in the text mode.Fix. We do away with
fseek()
andftell()
entirely and usestd::istreambuf_iterator
to read the whole file intostd::string
. The fix only applies on Windows.On Linux, we use
stat()
to measure the file size and then callread()
to read all the bytes in the file.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.
Please note that this is terribly slow.
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.
Slower than
std::fread()
? Note that this line is only supposed to run on platforms where POSIX is not available.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.
In https://social.msdn.microsoft.com/Forums/en-US/87e128e2-5320-4796-b4a2-36248f86a8ce/huge-performance-hit-when-using-ifstream-vs-fopen?forum=Vsexpressvc,
std::ifstream
shows competitive performance with respect tostd::fread()
.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.
Interesting as I just tried on Linux, it's about 10x slower. But I guess when file is that huge JSON would be the bottleneck here.