You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently when you read a large file using ioutil.ReadAll the following bad things happen:
ReadAll makes log(N) unnecessary allocations of total size N which become garbage.
ReadAll makes an unnecessary copy of N bytes.
ReadAll issues log(N) read requests (which is especially unpleasant for remote files).
ReadAll can over-allocate up to 2x more memory than necessary.
ReadAll should support Seeker interface, query size of (the remaining part of) the file, and use it as capacity hint (which is already present in the implementation). That would eliminate all of the above negative effects (no garbage, no overallocation, no small reads).
Don't do that. ReadAll is for Readers, not Files, and putting this kind of specialization into libraries is a recipe for long-term bloat.
Put another way, ReadAll is a simple, general convenience function. If you have performance concerns specific to a particular kind of input, program that case separately. Maybe make it a library function, but not part of ioutil.ReadAll.
Currently when you read a large file using ioutil.ReadAll the following bad things happen:
ReadAll should support Seeker interface, query size of (the remaining part of) the file, and use it as capacity hint (which is already present in the implementation). That would eliminate all of the above negative effects (no garbage, no overallocation, no small reads).
Objections?
@bradfitz
The text was updated successfully, but these errors were encountered: