-
Notifications
You must be signed in to change notification settings - Fork 474
Optimization - A queue with fixed storage size backed by a circular buffer #1262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this 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
Co-authored-by: Martin Evans <[email protected]>
This should provide some optimizations to the FixedQueue. My test are:
BEFORE THE CHANGES:
AFTER THE CHANGES: