性能优化,减少Lambda闭包分配
This commit is contained in:
@@ -52,8 +52,14 @@ public class DataRecordQueue : IDisposable
|
||||
{
|
||||
var charCount = record.FieldCharCount;
|
||||
LongestFieldCharCount = Math.Max(LongestFieldCharCount, charCount);
|
||||
if(_currentCharCount + charCount > _maxCharCount)
|
||||
await TaskExtensions.WaitUntil(() => _currentCharCount + charCount < _maxCharCount, 50);
|
||||
if (_currentCharCount + charCount > _maxCharCount)
|
||||
{
|
||||
// 不用Task.WaitUntil是为了防止产生Lambda闭包
|
||||
while (!(_currentCharCount + charCount < _maxCharCount))
|
||||
{
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
_queue.Add(record);
|
||||
Interlocked.Add(ref _currentCharCount, charCount);
|
||||
OnRecordWrite?.Invoke();
|
||||
|
@@ -133,7 +133,7 @@ public class CsvReader : IDataReader
|
||||
|
||||
if (!hasQuote && currChar == delimiter)
|
||||
{
|
||||
result.Add(source[start..(end)].ToString());
|
||||
result.Add(source[start..(end)].ToString()); // 超大型字符串会在LOH中分配内存,没救
|
||||
start = end + 1;
|
||||
++end;
|
||||
}
|
||||
|
Reference in New Issue
Block a user