aspnet/FileSystem

Idea to minimize buffer allocations in PhysicalFileProvider

davidfowl opened this issue · 7 comments

Credit goes to @stephentoub

Pass the minimum buffer size (1) to the FileStream constructor and have callers use pooled buffers for reading.

/cc @pakrym @Tratcher @rynowak

Would it read skipping internal buffer in this case?

That's the idea.

I'll try and profile it tomorrow.

Would be nice to allow passing 0 to bufferSize then.

While it may be nice aesthetically, it shouldn't really impact anything. The buffer shouldn't be allocated (at least not in corefx), as the buffer is lazily-initialized and will be skipped if the number of bytes to be read is >= bufferSize.

@pakrym did it help (if you got the chance to profile)?

Yes, I implemented it. Buffer allocations from FileStream are not a problem anymore.