19 Commits
Author SHA1 Message Date
xtaci 8261adb315 refactor: optimize performance with reduced lock contention and code deduplication
- bufferRing: add consumeFront() method to eliminate duplicate buffer
  consumption code in tryReadV1/tryReadV2, move allocator.Put() outside
  critical section to reduce lock hold time

- Session.IsClosed(): replace select-based check with atomic flag for
  faster hot path execution, add 'closed' field with atomic operations

- shaperQueue: convert count to atomic int64, Len() and IsEmpty() now
  lock-free using atomic.LoadInt64()

- recvLoop: move stream.fin() and stream.update() calls outside lock
  scope in cmdFIN/cmdUPD handlers to reduce lock contention

- stream: extract checkWriteClosed() helper to deduplicate close checks
  in writeV1/writeV2

All tests pass with race detector enabled.
2026-01-29 13:02:44 +08:00
xtaci cb81ae99ee perf: reduce memory allocations in hot paths
- Add writeRequestPool to reuse writeRequest objects and their result
  channels in session.go, reducing allocations per write operation

- Add shaperHeapPool to reuse shaperHeap objects in shaper.go, avoiding
  heap allocations when streams are created/destroyed

- Pre-allocate buffers and heads slices with capacity 8 in newStream()
  to reduce slice growth allocations during data transfer

Benchmark results (128KB data transfer):
  Before: 36 allocs/op, ~910 MB/s
  After:  20 allocs/op, ~950 MB/s

This reduces memory allocations by 44% and improves throughput by ~5%.
2026-01-25 22:56:15 +08:00
xtaci 3b4ec71231 optimize: avoid memory leak 2025-12-19 19:27:16 +08:00
xtaci 1865f272c3 use any to subsitute interface{} 2025-11-21 16:18:56 +08:00
xtaci 8168d2f9f9 remove unused variable 2025-11-19 18:17:20 +08:00
xtaci 18b1529e75 changed the data type of count in shaperQueue to int 2025-11-18 14:08:44 +08:00
xtaci 6d9a390b92 added comments 2025-11-18 14:07:50 +08:00
xtaci 4c94889167 O(1) deletion of streams 2025-11-17 20:06:01 +08:00
xtaci bac67e250f rename field name 2025-11-17 17:31:07 +08:00
xtaci 315621a5ad add coments for shaper 2025-11-17 17:27:02 +08:00
xtaci f251456b93 added shaperQueue for transmission queue management 2025-11-17 15:20:57 +08:00
xtaci 44d69f6d1a refine comments 2024-08-01 17:25:10 +08:00
xtaci 18a4b3cad9 elaborate comments on source codes 2024-07-28 22:10:35 +08:00
xtaci 28b48935d0 add license to source codes 2024-07-25 21:59:09 +08:00
xtaci 79ed6364e6 differentiate control frame and data frame 2023-02-14 22:19:42 +08:00
xtaci d5ca637a0e ignore prio settinn in writeFrameInternal 2023-02-07 22:06:41 +08:00
xtaci 5bfb5a97e0 fix a possible prio error 2023-02-07 21:23:07 +08:00
xtaci 09e2c01560 fix shaper prio overflow 2021-09-22 21:38:58 +08:00
xtaci 78fdaa98a6 add a shaper for fair transfer 2019-09-10 20:33:49 +08:00