24 Commits
Author SHA1 Message Date
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 53c14d4570 refactor: unify and simplify OOB handler interface for UDPSession
- Replace atomic.Pointer[func([]byte)] with atomic.Value for OOB callback storage to improve compatibility.
- Rename SetCallbackForOOB to SetOOBHandler and GetMaxSizeForOOB to GetOOBMaxSize for clearer, consistent API naming.
- Add locking in SendOOB to ensure thread safety during OOB packet construction.
- Update related test cases in sess_test.go to use the new interface names.
- Revise comments and documentation for better clarity and maintainability.

user takes care of the nil handler

use 0xffffffff as the seqid of OOB

return error on nil handler

fix race in test

shorten test data size

add more test on OOB

enhance Error test

allow nil from sender side

add OOBPackets in snmp

use dummy handler instead of resetting the atomic.Value

add test for dummy handler

remove a comment

formalize callback function prototype

use const

rename to expose

Add comments to clarify KCP input and FEC decoding order for FEC packets.

fix test

comments

add TestOOB_OneSideHandler
2025-12-27 23:25:03 +08:00
JinnBlue 0eccac26e1 feat(snmp): RingBufferSndQueue/RingBufferRcvQueue/RingBufferSndBuffer replace MaxLen with the more meaningful Len. (#303) 2025-11-05 17:16:44 +08:00
xtaci e228bdb064 remove unused header 2025-07-31 10:01:17 +08:00
xtaci 4338d9c2a6 use more strict discarding of shards 2025-06-09 19:44:37 +08:00
xtaci 27bc69b672 Squashed commit of the following:
commit a6eb09bcae
Author: xtaci <imap@live.com>
Date:   Mon Jun 9 16:51:56 2025 +0800

    added a test to FEC

commit 01641f964b
Author: xtaci <imap@live.com>
Date:   Mon Jun 9 15:43:12 2025 +0800

    rename snmp var

commit 32d49d392a
Author: xtaci <imap@live.com>
Date:   Mon Jun 9 15:41:52 2025 +0800

    update snmp

commit bd5c742170
Author: xtaci <imap@live.com>
Date:   Mon Jun 9 15:37:15 2025 +0800

    optimize

commit fdbe42618f
Author: xtaci <imap@live.com>
Date:   Mon Jun 9 15:17:35 2025 +0800

    fix getShardId

commit 4473f93581
Author: xtaci <imap@live.com>
Date:   Mon Jun 9 15:00:56 2025 +0800

    add more info to snmp

commit ff7cf0b51c
Author: xtaci <imap@live.com>
Date:   Mon Jun 9 14:53:32 2025 +0800

    optimize error handling

commit 4aa82fae89
Author: xtaci <imap@live.com>
Date:   Mon Jun 9 14:42:55 2025 +0800

    use heap to manager shard recovery in fec
2025-06-09 17:25:56 +08:00
xtaci 0a904d16b7 write snmp info 2025-06-08 12:10:15 +08:00
xtaci f1c5ec66e1 print ring buffer in SNMP 2025-06-07 21:56:25 +08:00
xtaci 3653cc9fea add license to source codes 2024-07-25 21:35:37 +08:00
xtaci 582575ef06 Squashed commit of the following:
commit a8ae293a9ddee042c35e2501f93fa5dfa2425302
Merge: bdaf81e 1a84985
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 22:48:13 2020 +0800

    Merge branch 'master' into autotune

commit bdaf81e88e
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 22:38:31 2020 +0800

    add loc

commit ce66a98f95
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 19:53:42 2020 +0800

    lint

commit ad7383d8a3
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 19:05:35 2020 +0800

    fix typo

commit dc0fc2364c
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 16:47:14 2020 +0800

    adjust tests

commit ec45b72c39
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 16:45:17 2020 +0800

    remove obsolete decoder in listener

commit 827aa70e29
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 16:42:42 2020 +0800

    use hierarchical defensive receiving strategy

commit f5ca6b0e3a
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 16:34:30 2020 +0800

    optimize condition

commit ff34f7683f
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 15:18:00 2020 +0800

    fix test

commit a08b274651
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 15:13:20 2020 +0800

    solve compability issue with non FEC sender

commit ab7596783b
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 15:02:34 2020 +0800

    implements autotune in fec decoder

commit 260f61b3eb
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 9 14:34:48 2020 +0800

    hack 16-bit to identify FEC from packet

commit 105bfec567
Author: xtaci <daniel820313@gmail.com>
Date:   Fri Oct 2 21:38:47 2020 +0800

    add autotune
2020-10-09 22:52:11 +08:00
xtaci a196621e9a add InPkts & OutPkts counters 2017-03-08 11:23:45 +08:00
xtaci f871d82e57 rename variables 2017-03-07 16:06:48 +08:00
xtaci 9e2c9be74a golint 2017-03-02 15:09:32 +08:00
xtaci 0b78747124 brought back early retransmit 2017-03-02 00:20:40 +08:00
xtaci 0f9370a01e fix fastresend resends too many packets 2017-03-01 16:11:22 +08:00
xtaci a56e81a416 rename 2017-01-09 16:55:00 +08:00
xtaci fe29c99670 record possible un-recoverable data shards 2017-01-09 16:10:10 +08:00
xtaci a67e3a7cf5 add Reset() to snmp 2016-12-21 10:49:38 +08:00
xtaci 6ed4f9e659 add Header() & ToSlice() to snmp 2016-12-20 21:55:24 +08:00
xtaci 51f71b5739 add some comments to snmp, add InBytes 2016-11-25 16:41:26 +08:00
xtaci f3887cb6be Revert "remove early retrans, use! fec instead"
This reverts commit 015bc070d7.
2016-11-05 11:01:46 +08:00
xtaci 015bc070d7 remove early retrans, use! fec instead 2016-10-25 16:40:47 +08:00
xtaci 5c61c4984f add snmp indicator KCPInErrors 2016-10-17 10:41:13 +08:00
xtaci 4976678721 lint 2016-06-29 22:18:39 +08:00