feat(stream): fast buffer freeing for large cache#1053
Merged
j2rong4cn merged 8 commits intoOpenListTeam:mainfrom Aug 16, 2025
Merged
feat(stream): fast buffer freeing for large cache#1053j2rong4cn merged 8 commits intoOpenListTeam:mainfrom
j2rong4cn merged 8 commits intoOpenListTeam:mainfrom
Conversation
This was referenced Aug 14, 2025
Closed
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a memory management optimization for large buffer allocations by adding support for anonymous mmap allocation. The feature enables faster memory freeing for large caches through a configurable threshold.
Key changes:
- Adds
MinMmapAllocSizeconfiguration option (default 4MB) to control when mmap allocation is used - Replaces
sync.Poolwith a custom genericPool[T]implementation for better type safety - Implements mmap-based buffer allocation for buffers exceeding the threshold size
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/pool/pool.go | Introduces new generic pool implementation with capacity limits |
| internal/stream/util.go | Updates buffer pool to use custom pool and mmap allocation for large buffers |
| internal/stream/stream.go | Adds mmap allocation support for file stream caching |
| internal/net/request.go | Refactors Buf struct to use direct byte slice with mmap support instead of bytes.Buffer |
| internal/conf/var.go | Adds MinMmapAllocSize configuration variable |
| internal/conf/config.go | Adds MinMmapAllocSize field to Config struct with default value |
| internal/bootstrap/config.go | Initializes MinMmapAllocSize from configuration |
| internal/stream/stream_test.go | Updates test configuration and test name |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: j2rong4cn <36783515+j2rong4cn@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: j2rong4cn <36783515+j2rong4cn@users.noreply.github.com>
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.
添加配置选项 mmap_thresholdMB
默认为4 单位:MB
大于或等于该大小的[]byte将使用
匿名mmap来达到快速释放内存占用的目的