explaingit

toicf/graintcp

Analysis updated 2026-05-18

58Audience · developerComplexity · 4/5LicenseSetup · moderate

TLDR

A single file Cloudflare Worker that relays VLESS traffic over WebSocket, tuned with several low level tricks to reduce networking overhead.

Mindmap

mindmap
  root((GrainTCP))
    What it does
      Relays VLESS over WebSocket
      Runs on Cloudflare Workers
    Tech stack
      Cloudflare Workers
      JavaScript
      VLESS protocol
    Use cases
      Serverless proxy relay
      Low level performance tuning
    Audience
      Developers optimizing Workers code
    Optimizations
      UUID parsed once at startup
      Upload packet batching
      Download chunk aggregation

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Deploy a VLESS over WebSocket relay on Cloudflare Workers without managing your own server.

USE CASE 2

Study how the code batches small outgoing packets to reduce the number of send calls.

USE CASE 3

See how large downloads are sent directly while small chunks are grouped before sending.

USE CASE 4

Adjust the concurrent connection setting when moving the code from Workers to Cloudflare Snippets.

What is it built with?

Cloudflare WorkersJavaScriptVLESS

How does it compare?

toicf/graintcpautomationsmanufaktur-labs/open-invoice-germanyballwictb/besur-themes
Stars585858
LanguageTypeScriptCSS
Setup difficultymoderatemoderateeasy
Complexity4/53/51/5
Audiencedeveloperpm founderdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · moderate Time to first run · 1h+

Relies on an undocumented Cloudflare Workers API and needs manual tuning of the concurrency setting outside Workers/Pages.

Free to use and modify, but any distributed version, including one used to run a service, must also be released under the same license.

In plain English

GrainTCP is a single JavaScript file that runs on Cloudflare Workers and acts as a relay for VLESS traffic sent over a WebSocket connection, allowing a client to reach the open internet through a Cloudflare Worker acting as a TCP proxy. The README describes it less as a project adding new protocol features and more as an exercise in squeezing extra performance out of the path data takes through the Worker. Rather than using Cloudflare's documented socket connection API, the code relies on an undocumented internal method it calls a grey area interface, which the author states still results in the same underlying TCP connection but through a smaller, less common code path. The README walks through several specific optimizations: moving the parsing of a client's identifying UUID out of the per request loop and into a one time setup step, which the author's own benchmarks show cutting matching time from around 53 nanoseconds to under 10, combining small outgoing data chunks into larger packets before sending them, guided by ideas borrowed from two existing streaming libraries, to reduce how often the underlying send function is called, and, for downloads, sending large chunks straight through immediately while only batching together chunks smaller than 32 kilobytes to cut down on the number of very small network frames. The README also documents a setting for how many TCP connections to attempt at once when first connecting, noting that the default of four assumes a normal Workers or Pages deployment and should be lowered to one if the code is instead run as a Cloudflare Snippet. A table lists every tunable value, including buffer sizes and thresholds, alongside their defaults. The project is released under the GPL 3.0 license, and the README links to a Telegram channel for discussion and to the two external libraries whose ideas informed the packet batching design.

Copy-paste prompts

Prompt 1
Explain what request.fetcher.connect() is and how it differs from the documented cloudflare:sockets API.
Prompt 2
Walk me through why parsing the UUID once at startup is faster than parsing it on every request.
Prompt 3
Help me understand the difference between the upload queue and the download aggregation logic.
Prompt 4
Show me what I need to change if I deploy this code as a Cloudflare Snippet instead of a Worker.

Frequently asked questions

What is graintcp?

A single file Cloudflare Worker that relays VLESS traffic over WebSocket, tuned with several low level tricks to reduce networking overhead.

What license does graintcp use?

Free to use and modify, but any distributed version, including one used to run a service, must also be released under the same license.

How hard is graintcp to set up?

Setup difficulty is rated moderate, with roughly 1h+ to a first successful run.

Who is graintcp for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.