Avoid char buffer allocations in System.IO.Compression#2694
Conversation
|
There was a problem hiding this comment.
Don't we do this all the time in String and StringBuilder for performance reasons, though? I realize that mundane tasks like this should avoid pointer arithmetic, but say if we had this in a performance-critical piece of code, then what are the guidelines?
There was a problem hiding this comment.
Don't we do this all the time in String and StringBuilder for performance reasons, though?
Yes, but that's inside String, the same type, and StringBuilder, which is effectively an extension of that type. To code outside of such types, string should be considered immutable, except in very rare circumstances. The mutability is effectively an internal implementation detail.
but say if we had this in a performance-critical piece of code, then what are the guidelines?
The guideline is don't do it. If there's an extremely compelling case for doing it in a particular situation, complete with scenarios and perf tests and no alternatives, then it's possible an exception would be made.
|
@Maxwe11 I've updated the fork to resolve these problems. |
|
Thanks for updating it, @James-Ko. LGTM. |
Avoid char buffer allocations in System.IO.Compression
Avoid char buffer allocations in System.IO.Compression Commit migrated from dotnet/corefx@21bf9a8
These changes avoid creating an intermediate
char[]buffer when creating a string.