Skip to content

remove ts fields from kcp segments, saving 4 bytes#1

Open
rookielighthouse wants to merge 3 commits into
net2share:masterfrom
rookielighthouse:master
Open

remove ts fields from kcp segments, saving 4 bytes#1
rookielighthouse wants to merge 3 commits into
net2share:masterfrom
rookielighthouse:master

Conversation

@rookielighthouse

Copy link
Copy Markdown

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.

Comment thread kcp.go Outdated
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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you also update the comment?

selfishblackberry177 added a commit to net2share/vaydns that referenced this pull request Mar 26, 2026
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>
@rookielighthouse

Copy link
Copy Markdown
Author

Comment is now fixed @selfishblackberry177

@selfishblackberry177

Copy link
Copy Markdown
Collaborator

@rookielighthouse Thanks for contribution. But this will be a breaking change for whoever use KCP, right? Is there a way around to this?

@rookielighthouse

Copy link
Copy Markdown
Author

@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.

@rookielighthouse

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants