fix(kcp): prevent zero-value override of window/buffer params causing 10x perf drop

The metadata parser unconditionally assigned GetInt results (which
return 0 for missing keys) to all KCP config fields, overwriting
defaults like SndWnd=1024, RcvWnd=1024, StreamBuf=2097152 with 0.

KCP's WndSize only applies positive values, so snd_wnd=0 caused
the write path condition waitsnd < s.kcp.snd_wnd to never succeed,
effectively stalling throughput at ~10Mbps instead of 400Mbps+.

- Only apply metadata values when the key actually exists (IsExists check)
- Use Clone() instead of sharing the global DefaultConfig pointer
- Add Config.Clone() deep-copy method
This commit is contained in:
sagitchu
2026-04-21 10:20:21 +08:00
parent bb48ab00bd
commit 37341af2d1
3 changed files with 99 additions and 28 deletions
+9
View File
@@ -89,6 +89,15 @@ func ParseFromFile(filename string) (*Config, error) {
return config, nil
}
// Clone returns a deep copy of the Config.
func (c *Config) Clone() *Config {
if c == nil {
return nil
}
clone := *c
return &clone
}
// Init initializes the KCP config.
func (c *Config) Init() {
switch c.Mode {