GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Reduce allocations in Get-Content cmdlet by iSazonov · Pull Request #8103 · PowerShell/PowerShell Conversation
|
| /// <param name="isRawStream"> | ||
| /// Indicates raw stream. | ||
| /// </param> | ||
| public FileSystemContentReaderWriter( |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why was this removed?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It is unneeded and used internal constructor and we can safely remove it. (Otherwise we have to fix it to follow our changes in another constructor with delimiter parameter.)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks good to me. I agree that the offset Dictionary could be a perf issue for simple delimiter characters. Have you performed any tests to verify perf gains? I imagine they would be significant, in some case, by switching to use Span.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| blocks.Add(contentRead); | ||
| } | ||
|
|
||
| return _reader.Peek() != -1; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this always have to be -1, when reading a raw stream to the end?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // we can read to generate another possible match. | ||
| // If we read more characters than this, we risk consuming | ||
| // more of the stream than we need. | ||
| _offsetDictionary = new Dictionary<char, int>(_delimiter.Length); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This looks a little bit dangerous. If _usingDelimiter is set to true anywhere else, _currentLineContent, _offsetDictionary will be null during later reads. I feel we should at least have an assert where these are used to ensure they are not null and as a warning if the code somehow gets changed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If somebody make the wrong change our tests will be crashed with null reference exception and we'll never merge the code. I don't know where we could set the assert and how it can help more then the null reference exception.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I don't found how quickly fix this. Will investigate.
No. I accidentally discovered this by reading code. Once I realized that we allocate in heap for every char in a worst case and for every line I did not see the point to run PerfView. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think this can be
_offsetDictionary[lowByte] = _delimiter.Length - i - 1;
For duplicate chars the last index will end up in _offsetDictionary[lowByte]
Also, do we need to be worried about char collisions using the low byte?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Also, do we need to be worried about char collisions using the low byte?
There is a comment in the code. If we have a file with chars from many languages we'll have many collisions and lost performance. In practice, we can expect that files contains chars from one-two languages. In the common case we'll have no collisions and best performance.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think this can be
Thanks! Good catch!
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
currentChar can be defined below where it is used.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
4a7488a to
07af4ca
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Andrew (@anmenaga) Steve Lee (@SteveL-MSFT) Have you any comments? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
* Simplify main loop in ReadDelimited() by bringing out raw stream code * Remove unused constructor * Allocate buffer for current line once in constructor * Use Span buffer to significantly reduce allocations * Optimize Boyer-Moore. Use simple mapping Unicode chars to byte. It works well for common text files with chars from one-two languages.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.