Optimization - A queue with fixed storage size backed by a circular buffer#1262
Merged
martindevans merged 9 commits intoSciSharp:masterfrom Sep 29, 2025
Merged
Optimization - A queue with fixed storage size backed by a circular buffer#1262martindevans merged 9 commits intoSciSharp:masterfrom
martindevans merged 9 commits intoSciSharp:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
martindevans
approved these changes
Sep 29, 2025
Member
martindevans
left a comment
There was a problem hiding this comment.
LGTM, just a couple of minor nits
Co-authored-by: Martin Evans <[email protected]>
This was referenced Feb 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This should provide some optimizations to the FixedQueue. My test are:
BEFORE THE CHANGES:
AFTER THE CHANGES: