fix: Peek OOM and performance issue #335
Merged
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.
What type of PR is this?
fix
Check the PR title.
(Optional) Translate the PR title into Chinese.
修复 Peek 调用导致的性能与内存问题
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
Originally, when we have data in more than one
linkBufferNode
,Each
Peek
call will create a new buffer for returning data, and put it in cache list.when the data grows larger, it would cause OOM if we can't release the cache in time.
This PR will reuse a
cachePeek
forPeek
for memory and performance friendly, especially peeking a large buffer.The
Next
method can also use the implementation like this one when it becomes stable.zh(optional):
在原来的实现里面,我们如果数据存放在多于一个的
linkBufferNode
,那么每次的
Peek
调用都会新建一个buffer来返回数据,并且会放在cache列表里。当数据增长,这会导致OOM问题,如果我们不能及时回收cache里的数据。
这个PR对于
Peek
调用会复用一个cachePeek
,对内存和性能更为友好,特别是peek数据量大的场景。当这个实现稳定后,
Next
方法也可以使用这方式来优化内存占用。(Optional) Which issue(s) this PR fixes:
(optional) The PR that updates user documentation: