- Replace division and modulo operations with bitwise equivalents:
- len(src) / 8 -> len(src) >> 3
- len(src) / 16 -> len(src) >> 4
- n / 8 -> n >> 3
- n % 8 -> n & 7
- Improve lock handling in blockCrypt:
- Split single mutex into separate encMu/decMu for encrypt/decrypt
- Remove defer for Lock/Unlock to reduce overhead
- Cache blockSize in struct to avoid repeated method calls
- Optimize Salsa20 and None ciphers:
- Skip unnecessary copy when dst and src point to same memory
- Add //go:nosplit directive to hot path functions
All encryption tests pass. Benchmark results show no regression with
zero memory allocations maintained (0 B/op, 0 allocs/op).
commit e51740f7e6
Author: xtaci <imap@live.com>
Date: Sat Jan 24 22:11:58 2026 +0800
optimize crypto using subtle/XORBytes
commit 071dc4a69d
Author: xtaci <imap@live.com>
Date: Sat Jan 24 21:55:49 2026 +0800
1. Fix incorrect RepeatSegs counter in parse_data() function
- Previously, the repeat flag was never set to true when duplicate packets
were detected, causing incorrect statistics reporting
- Added missing else branch to properly mark duplicate segments
- Impact: Correct tracking of repeated packet statistics
2. Fix memory leak in FEC decoder auto-tune functionality
- When FEC parameters were adjusted dynamically, the old shardSet map
was discarded without recycling its buffer pool entries
- Added proper cleanup loop to return old shard packets to buffer pool
before creating new shardSet
- Impact: Prevents memory growth during long-lived connections with
dynamic FEC parameter adjustments
Files modified:
- kcp.go: Added else branch in parse_data() to set repeat=true for duplicates
- fec.go: Added buffer cleanup loop before shardSet recreation in decode()
All existing tests pass, including FEC encoding/decoding and lossy connection tests.