214 Commits
Author SHA1 Message Date
xtaci 3b4ec04d35 fix typo 2026-03-13 17:21:53 +08:00
xtaci 8668391e92 perf: optimize bufferRing and shaperLoop for better throughput
- bufferRing: use bitmask instead of modulo for index calculation
  * Ensure capacity is always power of 2
  * Replace % with & for faster index wrapping in push/pop/grow/consumeFront

- shaperLoop: batch drain pending write requests
  * Collect multiple requests before notifying sendLoop
  * Reduces goroutine wake-up overhead under high load
2026-02-09 15:18:17 +08:00
xtaci 5c3cd5137f add protocol validation 2026-01-31 11:52:14 +08:00
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 c55575ea34 feat: autocleanup when both sides called CloseWrite() 2026-01-26 20:47:46 +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 c8a401fdb4 fix(session): reject cmdUPD in protocol version 1
cmdUPD is a v2-only command used for flow control window updates.
Previously, recvLoop would accept and process cmdUPD even when
the session was configured for protocol version 1, which violates
the protocol specification.

This change adds a version check before processing cmdUPD. If the
session is not running v2, it now correctly returns ErrInvalidProtocol
and terminates the receive loop.
2026-01-24 22:29:03 +08:00
xtaci a78910018b make the critical section small 2025-12-18 17:12:28 +08:00
xtaci 8684a3fa1a chores: rename variable for clarity 2025-12-14 13:51:35 +08:00
xtaci c9c21c1cd5 optmize: use simpler way to detect uint32 overflow 2025-12-14 13:45:06 +08:00
xtaci 3b644df082 add a comment 2025-12-14 12:59:31 +08:00
xtaci 18fbbf99f8 (chores): optimize function structure and allow writers to change the deadline during waiting for window update.
rename vars
2025-12-13 22:36:52 +08:00
xtaci 436b220390 chores: removed an useless notify in fin command, and optimized comments in session.go 2025-12-13 21:33:24 +08:00
xtaci 0f82c6d5d6 Merge branch 'rbqvq-dev' 2025-12-10 11:37:20 +08:00
Coia Prant 004a112bb0 refactor: remove else branch 2025-12-09 23:39:19 +08:00
xtaci af8d2e4868 remove 1 line of unreachable code 2025-11-24 13:32:02 +08:00
xtaci 3aef70af01 fix a bug that shaper channel is unbuffered 2025-11-23 11:27:07 +08:00
xtaci cded68b5a3 lower the freq to notify shaper 2025-11-23 11:14:13 +08:00
xtaci 6549b82bea lower the freq to notify shaper to accept new writeRequests 2025-11-23 11:08:19 +08:00
xtaci b72cddfd69 add a check before notify shaperLoop 2025-11-18 17:45:46 +08:00
xtaci 2a98f86ab1 adjust comments 2025-11-18 14:13:45 +08:00
xtaci ba55c1dd2e adjust shaper notify strategy 2025-11-18 10:18:42 +08:00
xtaci 4669622f28 use notify channel to sync sending states 2025-11-17 22:57:29 +08:00
xtaci 94d0f009d8 use notify mechanism between shaper and writeLoop 2025-11-17 22:43:25 +08:00
xtaci f251456b93 added shaperQueue for transmission queue management 2025-11-17 15:20:57 +08:00
lesismal 80f1038663 allocator optimization: avoid tmp obj's allocation and gc 2025-02-17 17:34:40 +08:00
xtaci d7000b4d71 move delete inside map check 2024-12-27 22:17:26 +08:00
xtaci 22957af8aa fix nil pointer exception 2024-12-27 22:10:54 +08:00
xtaci 56edb24703 disable finalizer 2024-11-19 13:50:43 +08:00
Coia Prant 41e6a518d8 fix: memory leak 2024-09-29 19:03:12 +08:00
xtaci 784d53ae55 recycle stream immediately if no object holds *Stream pointer 2024-09-15 21:55:22 +08:00
xtaci 52eaa2e163 comment on the scatter/gather IO 2024-09-08 20:55:19 +08:00
xtaci f6431c0c69 add a comment 2024-09-02 11:51:54 +08:00
xtaci 424eee0de7 rename writeFrame -> writeControlFrame for clarity 2024-08-31 21:57:47 +08:00
xtaci 4df635d3a6 recycle a closed packets 2024-08-31 21:36:12 +08:00
xtaci 44d69f6d1a refine comments 2024-08-01 17:25:10 +08:00
rkonfj 0384f8198b ErrTimeout implement the net.Error interface 2024-07-30 18:14:56 +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 bf0d5ac63f add openCloseTimeout for stream open and close 2023-02-14 21:56:01 +08:00
xtaci 46a59b2e89 only keep writeFrame with a default timeout 2023-02-14 21:46:07 +08:00
xtaci dbf64f502a always timeout for writeFrame 2023-02-14 20:33:47 +08:00
xtaci f8f99c6782 set write timeout only 2023-02-14 20:15:44 +08:00
fuli 5e66fda554 implement r/w timeout on smux for proper termination of session 2023-02-14 19:09:09 +08:00
xtaci a54d6cb361 control of shaper heap size 2023-02-12 19:51:18 +08:00
xtaci 5bfb5a97e0 fix a possible prio error 2023-02-07 21:23:07 +08:00
Zachary Zhao c76d829b38 In this commit a CloseChan function is added to session module
By this using this funcion, one can be notified immediately when a session is closed.
2022-11-24 19:25:00 +08:00
xtaci 09e2c01560 fix shaper prio overflow 2021-09-22 21:38:58 +08:00
sintanial e3f47c7785 add ability to turn off keepalive 2020-05-23 10:58:26 +03:00