remove ts fields from kcp segments, saving 4 bytes#1
Conversation
| IKCP_ACK_FAST = 3 // fast retransmit trigger threshold (duplicate ACK count) | ||
| IKCP_INTERVAL = 100 // default flush interval (ms) | ||
| IKCP_OVERHEAD = 24 // per-segment header size: conv(4) + cmd(1) + frg(1) + wnd(2) + ts(4) + sn(4) + una(4) + len(4) | ||
| IKCP_OVERHEAD = 20 // per-segment header size: conv(4) + cmd(1) + frg(1) + wnd(2) + ts(4) + sn(4) + una(4) + len(4) |
There was a problem hiding this comment.
Would you also update the comment?
Experimenting with net2share/kcp-go#1 which removes the ts fields from KCP segments, saving 4 bytes per segment. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Comment is now fixed @selfishblackberry177 |
|
@rookielighthouse Thanks for contribution. But this will be a breaking change for whoever use KCP, right? Is there a way around to this? |
This will indeed break backward compatibility. Unfortunately, there are no flags indicating the KCP version being used. However, an initial negotiation between the server and clients will resolve this issue. I believe this is required if further changes are to be made to the KCP protocol. |
|
KCP was originally designed to have a lower latency than TCP, which meant introducing more overhead. Reducing this overhead is vital for overcoming the harsh status of the Internet in Iran. With MTU=50, almost half the transmitted data consists of KCP headers. Lowering this overhead will significantly improve the connection speed in situations such as those in Iran. |
This change removes the 4-byte timestamp (ts) field from the KCP segment header, reducing per-segment overhead from 24 to 20 bytes. Previously, the sender embedded a timestamp in each segment and the receiver echoed it back in ACKs for RTT calculation. Instead, the sender now tracks send timestamps locally in a sent_ts map keyed by sequence number, and computes RTT when it receives an ACK by comparing the current time against the stored timestamp.