Library / SDK
xtaci/kcp-go avatar
xtaci/kcp-go

xtaci/kcp-go: the flush loop, the clock and the buffer pool behind Reliable UDP

A crypto-secure Reliable-UDP library for Golang with FEC support.

4,552 stars808 forksGoMIT

At a glance

What is it?
A Go Reliable-UDP library whose README argues its design in numbers, from a 20 ms retransmission loop where a container list costs 43.5 percent of a core and a fixed 1500 byte buffer pool.
Who is it for?
Adopt it when a TCP shaped API is needed over lossy links and you can accept a UDP transport, since the win comes from retransmission timing and forward error correction rather than from a protocol guarantee nobody makes. Read the design notes before sizing a server, because they note that their benchmark figures are workload- and hardware-specific, and check which release you pin: the latest tag is v5.7.2 from 2026-10-31, and the last push was on 2026-11-02.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly Go, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • xtaci/kcp-go4,552 ★ · -3
Star history
Repository2026-09-232026-11-15
xtaci/kcp-go4.6k4.6k

-3 Stars in the last 53 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The 20 ms flush is where slice beats list by two orders of magnitude

kcp.flush() scans the in-flight send buffer to find segments that need transmission or retransmission, so the data structure holding that queue is on the hot path of the whole library. The README benchmarks a sequential loop over a slice against the same loop over a container list, and the numbers are not close: 0.39 ns per operation for the slice against 54.6 ns for the list. The stated reason is cache behaviour, since the list structure introduces heavy cache misses while the slice has better locality. Scaled to a real server, 5,000 connections with a 32 packet window and the 20 ms interval, the slice costs 6 microseconds per flush, which is 0.03 percent of a CPU, while the list costs 8.7 ms, which is 43.5 percent.

code
BenchmarkLoopSlice-4   	2000000000	         0.39 ns/op
BenchmarkLoopList-4   	100000000	        54.6 ns/op

One clock read per flush, at a fixed 78 microseconds per 5000 connections

Timing is treated as a correctness concern, because an inaccurate RTT estimator produces false retransmissions, and false retransmissions are wasted bandwidth on a link that was already struggling. The cost of reading the clock is therefore measured too: a historical benchmark puts time.Now() at 15.6 ns/op, which the README says is not a portable performance guarantee. KCP uses currentMs(), which derives elapsed monotonic time from a package reference point, and the number of clock reads varies with the flush path: KCP samples time while checking retransmission deadlines and when preparing transmissions.

code
BenchmarkNow-4         	100000000	        15.6 ns/op

Every buffer is a 1500 byte slice taken from one global pool

Many packet buffers come from the package-wide `defaultBufferPool`, in fixed capacity chunks of 1500 bytes, the value the README calls mtuLimit. Buffers are returned to the pool when they are no longer needed, reducing repeated allocations. The subtler part is the garbage collector interaction: the pool uses sync.Pool, so the Go runtime may discard pooled buffers during garbage collection, and reuse and retention are not guaranteed.

Encryption hides the KCP and FEC headers, not just the body

Packet level encryption is built into the library rather than left to a tunnel, including AEAD for packet-level integrity and authentication. The README is careful about the limit: encryption can hide packet contents, but random per-packet nonces do not make network traffic anonymous, and endpoints, packet sizes, timing and traffic volume may still be observable.

Forward error correction comes from a pinned Reed-Solomon dependency

Loss is handled on two fronts, retransmission and recovery, and the second one is FEC using Reed-Solomon codes. The module manifest pins the implementation, with github.com/klauspost/reedsolomon at v1.14.2 as the direct dependency that provides it. The rest of the direct dependency list is small and tells you what the library does not do: crypto and network primitives come from the golang.org/x modules, with x/crypto at 0.58.0, x/net at 0.61.0, x/sys at 0.49.0 and x/time at 0.16.0, and error handling from github.com/pkg/errors. The module path carries a major version suffix, github.com/xtaci/kcp-go/v5, and it declares go 1.26.0, so building it needs a recent Go.

Three file pairs split the generic path from the Linux batch syscall path

The file layout mirrors the platform story. There are three pairs of platform files, platform_generic.go beside platform_linux.go, readloop_generic.go beside readloop_linux.go, and tx_generic.go beside tx_linux.go, which is how the batched, platform-specific UDP I/O the README advertises stay out of the build for other systems. Tracing is handled the same way, with kcp_trace_on.go and kcp_trace_off.go sitting apart from kcp.go itself. The remaining files are the mechanisms already described: bufferpool.go for the buffer pool, crypt.go for the ciphers, entropy.go for the nonce source, fec.go for the Reed-Solomon path, ringbuffer.go for the in-flight send buffer, timedsched.go for scheduling, sess.go for the session, readloop.go for the receive side, and snmp.go for the counters. There is also a wireshark directory, so captured packets can be inspected rather than guessed at.

The transport swap is one interface, not a new API

The adoption story is deliberately narrow: the library implements net.Conn and net.Listener, so code that already speaks the standard library stream interfaces can be pointed at it, though the README notes the familiar interface does not make the transport TCP. Around that, the README says it is designed for high concurrency with a shared timer scheduler, and that capacity depends on workload, configuration, and hardware. It is based on skywind3000's KCP, with additional features and optimizations. The stated deployments span a range of devices and applications, including online games, live broadcasting, file synchronization and network acceleration.

One release tag, and pushes that came after it

Three recent tags are listed, v5.7.2 on 2026-10-31, v5.6.73 on 2026-10-21 and v5.6.64 on 2026-01-26, and the default branch master received its last push on 2026-11-02. The module path carries a v5 suffix, so version selection happens at the import path rather than through a branch. Badges point at GoDoc, a codecov coverage graph, Sourcegraph and a KCP-Powered link, and the license file is MIT. There is no homepage field set for the repository, and the documentation is delivered as godoc on the versioned module path rather than as a site of its own.

Editorial conclusion

Adopt it when a TCP shaped API is needed over lossy links and you can accept a UDP transport, since the win comes from retransmission timing and forward error correction rather than from a protocol guarantee nobody makes. Read the design notes before sizing a server, because they note that their benchmark figures are workload- and hardware-specific, and check which release you pin: the latest tag is v5.7.2 from 2026-10-31, and the last push was on 2026-11-02.

Frequently asked questions

What is the KCP protocol?

It is a protocol that delivers an ordered, error-checked stream over UDP, and kcp-go is the Go implementation of it, based on skywind3000's KCP. It implements net.Conn and net.Listener, and adds Reed-Solomon forward error correction plus packet level encryption.

What does KCP stand for?

The acronym is not expanded in the README's introduction. What is documented is that kcp-go is a Reliable-UDP library for Go that is based on skywind3000's KCP, and the project carries a KCP-Powered badge linking to that C repository.

Does kcp-go encrypt its traffic, and what does that hide?

Yes. Optional packet encryption is built in, including AEAD for packet-level integrity and authentication. The README states that encryption can hide packet contents, but random per-packet nonces do not make network traffic anonymous: endpoints, packet sizes, timing and traffic volume may still be observable.

Official sources

  1. Issues
  2. License: MIT
  3. README
  4. Releases
  5. xtaci/kcp-go on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/xtaci-kcp-go.svg)](https://hysenlabs.com/projects/xtaci-kcp-go)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/xtaci-kcp-go.svg)](https://hysenlabs.com/projects/xtaci-kcp-go)

Was this useful?