462 Commits
Author SHA1 Message Date
xtaci 3b4ec04d35 fix typo v1.5.57 2026-03-13 17:21:53 +08:00
xtaci 911621421b go fix ./... 2026-02-19 11:43:58 +08:00
xtaci cf75cc7890 perf(stream): cache window update threshold to reduce computation
Add windowUpdateThreshold field to stream struct to cache the
MaxStreamBuffer/2 calculation. This avoids repeated pointer
dereferences (s.sess.config.MaxStreamBuffer) and integer division
on every tryReadV2() and writeToV2() call in the hot path.

- Add windowUpdateThreshold uint32 field to stream struct
- Initialize threshold in newStream()
- Use cached value in tryReadV2() and writeToV2()
v1.5.56
2026-02-09 15:37:33 +08:00
xtaci 532973c12c perf(stream): optimize Read by hoisting version check out of loop
Move protocol version check from inside the read loop to outside,
eliminating per-iteration switch statement overhead. The version
is constant for the stream's lifetime, so checking once is sufficient.

Before: switch inside for loop (branch on every iteration)
After:  if-else with separate loops (branch once per Read call)
2026-02-09 15:25:16 +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 e36a5bf87e Merge branch 'dev' v1.5.55 2026-01-29 13:07:30 +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 a3d8abef06 Merge branch 'dev' v1.5.54 2026-01-27 22:02:54 +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 6a7a88458f Merge branch 'dev' 2026-01-26 21:17:59 +08:00
xtaci 3b95be5bc9 fix a test 2026-01-26 21:15:53 +08:00
xtaci 4ab6361bcd Squashed commit of the following:
commit c55575ea34
Author: xtaci <imap@live.com>
Date:   Mon Jan 26 20:47:46 2026 +0800

    feat: autocleanup when both sides called CloseWrite()

commit baf236b97a
Author: xtaci <imap@live.com>
Date:   Mon Jan 26 18:20:43 2026 +0800

    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 20:59:01 +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 ab9f0f36cb Merge branch 'dev' v1.5.53 2026-01-26 15:17:53 +08:00
xtaci 4af4b02304 use bufferRing in stream.go to reduce memory allocations 2026-01-26 15:17:20 +08:00
xtaci bac164dea7 Merge branch 'dev' 2026-01-26 14:35:46 +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 a76bdd49fd Merge branch 'dev' v1.5.52 2026-01-25 22:56:40 +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 c4b7d47a00 Squashed commit of the following:
commit c8a401fdb4
Author: xtaci <imap@live.com>
Date:   Sat Jan 24 22:29:03 2026 +0800

    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.
v1.5.51
2026-01-24 22:29:37 +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