448 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 d4bebcc43b (test): Add internal stream unit tests covering waitRead, sendWindowUpdate, stopTimer, and writeV2 branches, raising coverage to 91.7% and revalidating test/coverage output. 2026-01-27 12:25:00 +08:00
xtaci 3b95be5bc9 fix a test 2026-01-26 21:15:53 +08:00
xtaci c55575ea34 feat: autocleanup when both sides called CloseWrite() 2026-01-26 20:47:46 +08:00
xtaci baf236b97a feat(stream): implement TCP half-close support via CloseWrite()
Add CloseWrite() method to enable TCP-like half-close semantics without
protocol changes. This allows one side to signal EOF while still receiving
data from the peer.

Changes:
- Add chWriteClosed channel to track local write-side closure
- Add CloseWrite() method that sends FIN but keeps read side open
- Modify writeV1/writeV2 to check local write state instead of remote FIN
- Update Close() to also close write side for backward compatibility

The existing cmdFIN protocol command is reused - CloseWrite sends FIN to
signal write completion while the stream remains readable.

Usage:
  stream.Write(data)
  stream.CloseWrite()  // send FIN, can still read
  io.ReadAll(stream)   // read peer's response
2026-01-26 18:20:43 +08:00
xtaci 4af4b02304 use bufferRing in stream.go to reduce memory allocations 2026-01-26 15:17:20 +08:00
xtaci e2bbc82e3e Remove per-iteration buffer realloc in benchmark to cut noise.
Improve throughput and lower allocations in BenchmarkConnSmux.
2026-01-26 14:34:00 +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 8dbcbb3da5 update header diagram v1.5.50 2025-12-22 17:52:04 +08:00
xtaci 5a2ce88084 fix readme 2025-12-21 21:27:38 +08:00
xtaci 353ea28299 refine readme 2025-12-21 21:24:51 +08:00
xtaci f6987ac177 fix chinese readme 2025-12-21 17:45:28 +08:00
xtaci 9ffe1ca9d3 optimize chinese readme 2025-12-21 12:04:59 +08:00
xtaci 31c31ad521 Add files via upload 2025-12-21 11:47:39 +08:00
xtaci 791402fd48 add Reference section 2025-12-21 11:43:58 +08:00
xtaci cbdd1a6d0c update README 2025-12-20 19:37:35 +08:00
xtaci a947aa6edf update README 2025-12-20 19:24:24 +08:00
xtaci 7188ee01aa update README 2025-12-20 19:22:53 +08:00
xtaci 091ca6f2d8 add chinese readme 2025-12-20 19:19:19 +08:00
xtaci 4576cac032 add more tests for session and shaper
uncomment
2025-12-19 19:57:52 +08:00
xtaci 2e3badcf3d add more test for shaper 2025-12-19 19:31:36 +08:00
xtaci 3b4ec71231 optimize: avoid memory leak 2025-12-19 19:27:16 +08:00
xtaci 02f4e56db0 add AGENTS.md 2025-12-19 15:56:33 +08:00
xtaci 13204104b9 add testcase to alloc_test.go 2025-12-19 12:48:49 +08:00
xtaci 129520968d Fix memory leak caused by buffer capacity modification during read operations preventing successful allocator recycling. v1.5.49 2025-12-19 12:26:17 +08:00
xtaci bbc15a0bcb Merge branch 'dev' v1.5.48 2025-12-18 17:56:40 +08:00
xtaci b7a5d16a75 properly stop the timer to avoid resource leaks, and add a limit for MaxReceiveBuffer
uncomment
2025-12-18 17:54:27 +08:00
xtaci e49a716823 make numWritten consistent 2025-12-18 17:14:12 +08:00
xtaci a78910018b make the critical section small 2025-12-18 17:12:28 +08:00
xtaci 60be49e34a optimize README.md 2025-12-17 21:36:40 +08:00
FULI 9d6ba58882 Add files via upload 2025-12-14 19:52:30 +08:00
FULI 9eefa8add2 Add files via upload 2025-12-14 19:40:03 +08:00
xtaci 9275ee358c fix TestGetDieCh testcase
fix TestGetDieCh
v1.5.47
2025-12-14 18:01:21 +08:00
xtaci d3df2cdee1 add comments 2025-12-14 15:23:59 +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
FULI 35dc1542bc Add files via upload 2025-12-14 11:59:24 +08:00
FULI d422478db8 Add files via upload 2025-12-14 11:57:31 +08:00
FULI d9e70a4dd0 Add files via upload 2025-12-14 11:49:35 +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 782c885721 optimize test for large bulk of data transfer 2025-12-11 21:18:47 +08:00
xtaci d6a40fdff0 upd v1.5.46 2025-12-10 13:57:38 +08:00
xtaci 0f82c6d5d6 Merge branch 'rbqvq-dev' v1.5.45 2025-12-10 11:37:20 +08:00
xtaci 18a98822ed add random length send for 1GB 2025-12-10 11:27:11 +08:00
xtaci eeb8413475 add functions to test data transfer for 8GB 2025-12-10 11:27:11 +08:00
xtaci af7a8d72d4 add random length send for 1GB 2025-12-10 10:06:23 +08:00
xtaci 1889f622bb add functions to test data transfer for 8GB 2025-12-10 09:56:20 +08:00