16 Commits
Author SHA1 Message Date
xtaci 46408de74f fix(timedsched): ensure minimum 2 sched workers to prevent starvation on single-CPU machines 2026-03-27 14:08:49 +08:00
xtaci fec60d1ec6 docs: improve code readability with structured comments and section headers
- kcp.go: Group protocol constants by category (RTO, commands, probe flags,
  window/MTU defaults, protocol parameters) with descriptive comments.
  Document KCP struct fields with protocol semantics (RFC 6298/5681/6937).
  Add 6-phase description to flush() and annotate each phase.

- sess.go: Add section separators for session, packet input pipeline, listener,
  and public API. Document postProcess() 3-stage pipeline and kcpInput()
  packet demultiplexing logic.

- fec.go: Document FEC constants (header sizes, packet types, maxShardSets).
  Clarify fecDecoder's auto-tuning mechanism.

- crypt.go: Add section header for CFB-mode encryption. Document encrypt/decrypt
  dispatch and 8x loop unrolling optimization strategy.

- timedsched.go: Document two-stage pipeline architecture (prepend → sched)
  and explain why stages are separated.

- autotune.go: Expand FindPeriod() documentation with algorithm description
  and fix ASCII signal diagram alignment.

- ringbuffer.go: Document RINGBUFFER_MIN and RINGBUFFER_EXP constants.

- snmp.go: Fix typos (accmulated → accumulated, retransmited → retransmitted).

No code logic changes. All modifications are comments only.
2026-03-13 17:01:51 +08:00
xtaci 2693fa8e71 perf: reduce heap allocations and fix memory leaks across multiple components
Optimizations:
- ringbuffer: optimize Len(), IsEmpty(), Discard(), Clear() methods with
  branchless arithmetic and simplified logic
- fec: fix memory leak in shardHeap.Pop() by setting element to nil before
  truncating slice, preventing GC from holding stale references
- timedsched: fix memory leak in timedFuncHeap.Pop() with same nil-before-truncate
  pattern; optimize prepend() using slice swap instead of append
- autotune: add sortCache field to Autotuner to reuse slice allocation in
  FindPeriod(), avoiding repeated allocations during period detection
- snmp: replace fmt.Sprint with strconv.FormatUint for better performance
  in Copy() and Reset() methods
- entropy: remove defer overhead in rngAES.Read() and rngChacha8.Read()
  hot paths for reduced function call cost
- bufferpool: pre-allocate ErrBufferPoolSizeExceeded error; reset slice
  length on Put() to allow proper reuse
- sess: remove defer overhead in 6 setter methods (SetWriteDelay,
  SetWindowSize, SetStreamMode, SetACKNoDelay, SetDUP, SetNoDelay)

These changes reduce memory allocations, fix potential memory leaks in
heap-based data structures, and eliminate defer overhead in frequently
called methods.
2026-01-29 12:22:33 +08:00
xtaci f53a3373f8 optimize: modernize -fix -test . 2025-12-22 13:10:47 +08:00
xtaci 91e7483fc9 use any to substitute interface{} 2025-11-21 16:24:14 +08:00
Coia Prant da3a437911 fix: memory leak (#279) 2024-10-04 12:51:53 +08:00
xtaci 3040333ea6 adjust comments 2024-07-27 21:54:02 +08:00
xtaci 3653cc9fea add license to source codes 2024-07-25 21:35:37 +08:00
xtaci 831b5b2673 properly drain timer.C 2020-03-22 22:01:17 +08:00
xtaci 6f9c25ae24 optimize on timedsched 2020-03-22 21:47:17 +08:00
xtaci dae4131c3f bugfix in timer 2020-03-09 21:24:19 +08:00
xtaci aa20c34d98 use absolute time 2020-01-05 11:48:19 +08:00
xtaci 9146e93d2d prevent slice from holding reference to closure 2020-01-05 00:02:09 +08:00
xtaci 3b36308a0c optimize timedsched memory allocation 2020-01-04 23:46:31 +08:00
xtaci 0d837e2e59 optimize timedsched 2020-01-04 23:22:54 +08:00
xtaci 42776b0b08 add a library level timedsched.go 2020-01-04 17:03:09 +08:00