dotnet/runtime

TakeLast Performance Improvement suggestion

Open

#118,312 建立於 2025年8月3日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)C# (17,886 star) (5,445 fork)batch import
area-System.Linqhelp wantedtenet-performance

描述

TakeRangeFromEndIterator uses a regular Queue <T>when IsStartIndexFromEnd, but this process can be done without intervening yields, allowing optimization using ArrayPool and Span.

https://github.com/dotnet/runtime/blob/3f25a276772b8d0e54452321e7525b7a176aa4a7/src/libraries/System.Linq/src/System/Linq/Take.cs#L111C13-L154C18

Below is the PR I did on ZLinq. https://github.com/Cysharp/ZLinq/pull/207/files Unlike ZLinq, a ToArray is required at the end of the queueing for Linq, but it will be similar.

貢獻者指南