Skip to content

Conversation

SignalRT
Copy link
Collaborator

This should provide some optimizations to the FixedQueue. My test are:

BEFORE THE CHANGES:

image

AFTER THE CHANGES:

image

@SignalRT SignalRT requested a review from Copilot September 28, 2025 17:38
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the FixedQueue implementation by replacing the naive List-backed approach with a circular buffer, along with several other performance improvements throughout the codebase. The changes focus on reducing memory allocations and improving computational efficiency.

  • Reimplemented FixedSizeQueue using a circular buffer instead of List with Remove operations
  • Optimized string concatenation in StreamingTokenDecoder using spans where available
  • Replaced LINQ operations with more efficient alternatives in multiple executors and BatchedExecutor

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
LLama/Common/FixedSizeQueue.cs Complete rewrite using circular buffer architecture with optimized enqueue/dequeue operations
LLama/StreamingTokenDecoder.cs Optimized string creation using CollectionsMarshal.AsSpan for .NET 5+
LLama/LLamaExecutorBase.cs Added AntipromptProcessor integration and optimized session token management
LLama/LLamaInteractExecutor.cs Replaced token-based antiprompt checking with string-based AntipromptProcessor
LLama/LLamaInstructExecutor.cs Replaced token-based antiprompt checking with string-based AntipromptProcessor
LLama/Batched/BatchedExecutor.cs Optimized batch queue management using head pointer instead of RemoveAt operations
LLama/AntipromptProcessor.cs Minor variable rename for clarity
LLama.Benchmark/Collections/FixedSizeQueueBenchmark.cs Added benchmark tests for the new FixedSizeQueue implementation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Member

@martindevans martindevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a couple of minor nits

@martindevans martindevans merged commit 1de246c into SciSharp:master Sep 29, 2025
7 checks passed
@SignalRT SignalRT deleted the Optimization branch October 3, 2025 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants