Skip to content

perf:优化stream#25

Merged
whki merged 2 commits intomainfrom
dev
Jul 25, 2025
Merged

perf:优化stream#25
whki merged 2 commits intomainfrom
dev

Conversation

@whki
Copy link
Copy Markdown
Contributor

@whki whki commented Jul 25, 2025

No description provided.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Bugbot free trial expires on July 29, 2025
Learn more in the Cursor dashboard.

Comment thread window/tumbling_window.go Outdated
// 通道已满,丢弃结果并更新统计信息(已在锁内)
tw.droppedCount++
// 将resultData放回池中
tumblingResultPool.Put(resultData)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Window Trigger Memory Leak and Corruption

Improper object pool management in TumblingWindow and SlidingWindow's Trigger methods causes memory leaks and potential data corruption.

  1. resultData slices, retrieved from pools, are only returned when the output channel is full; successful sends to the channel leak these slices.
  2. newData slices, also from pools, are assigned to the window's internal data field. This permanently holds pooled slices, preventing their return and risking data corruption if the pool reuses their underlying arrays.
    Code comments acknowledge these issues but offer no resolution for proper resource return.
Locations (2)

Fix in CursorFix in Web

Comment thread aggregator/group_aggregator.go Outdated
}

// 注意:不能将result放回池中,因为调用者还在使用
// group maps也不能立即放回池中,因为它们在result中被引用
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Memory Leak in Object Pool Usage

The GetResults() method suffers from an object pool memory leak. The result slice and individual group maps retrieved from sync.Pools are never returned to their respective pools. This leads to pool depletion, negating performance benefits and causing continuous new allocations, as acknowledged by the existing code comments.

Locations (1)

Fix in CursorFix in Web

Comment thread window/sliding_window.go Outdated
}

// 注意:newData不能放回池中,因为它现在是sw.data
// resultData也不能放回池中,因为它可能还在输出通道中被使用
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Sliding Window Memory Leak

The SlidingWindow.Trigger method suffers from object pool memory leaks. Slices retrieved from sw.rowPool (newData) are assigned to sw.data but are never returned to the pool. Similarly, slices from sw.resultPool (resultData) are only returned if the output channel send fails; otherwise, they are sent via the channel but never returned to the pool. This leads to gradual pool depletion. Additionally, a comment regarding resultData's return policy is misleading.

Locations (1)

Fix in CursorFix in Web

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jul 25, 2025

Codecov Report

Attention: Patch coverage is 31.73077% with 71 lines in your changes missing coverage. Please review.

Project coverage is 49.86%. Comparing base (b7ed499) to head (36a23f6).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
stream/stream.go 31.73% 69 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #25      +/-   ##
==========================================
- Coverage   49.95%   49.86%   -0.09%     
==========================================
  Files          45       45              
  Lines       11691    11755      +64     
==========================================
+ Hits         5840     5862      +22     
- Misses       5374     5415      +41     
- Partials      477      478       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread stream/stream.go Outdated
Comment thread stream/stream.go
@whki whki changed the title perf:使用对象池优化性能 perf:优化stream Jul 25, 2025
Comment thread stream/stream.go Outdated
@whki whki merged commit ca24ca7 into main Jul 25, 2025
5 checks passed
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