Skip to content

TakeLast Performance Improvement suggestion #118312

Open

Description

@akeit0

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.

Activity

  1. added
    untriaged
    on Aug 3, 2025
  2. added
    needs-area-label
    on Aug 3, 2025
  3. added and removed
    needs-area-label
    on Aug 3, 2025
  4. dotnet-policy-service commented on Aug 3, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-linq
    See info in area-owners.md if you want to be subscribed.

  5. jeffhandley commented on Aug 4, 2025

    @jeffhandley
    Member

    Thanks for the suggestion, @akeit0. If you can verify the gains using existing or new benchmarks in dotnet/performance, we'd consider accepting a pull request for this.

  6. added
    tenet-performance
    help wanted
    and removed
    untriaged
    on Aug 4, 2025
  7. added this to the Future milestone on Aug 4, 2025
  8. Ashutosh1028 commented on Dec 2, 2025

    @Ashutosh1028

    I’d like to work on this. Any additional guidance or constraints before I start?

  9. P4suta commented on Nov 8, 2026

    @P4suta

    Working on the TakeLast(1) case for sources whose count is unknown.

    AI generated this contribution.

  10. P4suta commented on Nov 8, 2026

    @P4suta

    Implemented in #137157.

    AI generated this contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Linqhelp wantedtenet-performance

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions