Skip to content

Commit 9682183

Browse files
authored
Merge pull request #5 from BackendStack21/perf/preload-and-fast-path
FastHTTP migration and performance improvements
2 parents 601ab32 + b90ffa6 commit 9682183

39 files changed

+2922
-1600
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
1616

1717
- name: Set up Go
18-
uses: actions/setup-go@v5
18+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
1919
with:
2020
go-version-file: go.mod
2121
cache: true
@@ -28,3 +28,9 @@ jobs:
2828

2929
- name: Test
3030
run: go test -race ./...
31+
32+
- name: Install govulncheck
33+
run: go install golang.org/x/vuln/cmd/govulncheck@latest
34+
35+
- name: Run govulncheck
36+
run: govulncheck ./...

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Checkout
17-
uses: actions/checkout@v4
17+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
1818
with:
1919
fetch-depth: 0
2020

2121
- name: Set up Go
22-
uses: actions/setup-go@v5
22+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
2323
with:
2424
go-version-file: go.mod
2525
cache: true
@@ -28,7 +28,7 @@ jobs:
2828
run: go test -race ./...
2929

3030
- name: Run GoReleaser
31-
uses: goreleaser/goreleaser-action@v6
31+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6
3232
with:
3333
distribution: goreleaser
3434
version: "~> v2"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Build output
22
/bin/
33
/dist/
4+
/static-web
45

56
# Test and coverage artifacts
67
coverage.out

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
## v1.3.0 (2026-03-08)
2+
3+
### Perf
4+
5+
- **server**: migrate HTTP layer from net/http to fasthttp — ~141k req/sec (55% faster than Bun)
6+
- **server**: use `tcp4` listener to eliminate dual-stack overhead (2x throughput gain on macOS)
7+
8+
### Refactor
9+
10+
- **handler**: replace `http.ServeContent` with custom `parseRange()`/`serveRange()` for byte-range requests
11+
- **compress**: convert gzip middleware from wrapping `ResponseWriter` to post-processing response body
12+
- **security**: use `ctx.SetStatusCode()`+`ctx.SetBodyString()` instead of `ctx.Error()` to preserve headers
13+
- **cache**: change `CachedFile` header fields from `[]string` to `string`
14+
15+
### Build
16+
17+
- **benchmark**: add fasthttp/net-http hello world baselines and update baremetal script
18+
119
## v1.2.0 (2026-03-07)
220

321
### Feat

CLI.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ Grouped by concern for readability. All flags are optional; unset flags do not o
186186
|------|------|---------|--------------|
187187
| `--host` | string | `` (all interfaces) | `server.addr` (host part) |
188188
| `--port`, `-p` | int | `8080` | `server.addr` (port part) |
189+
| `--redirect-host` | string || `server.redirect_host` |
189190
| `--tls-cert` | string || `server.tls_cert` |
190191
| `--tls-key` | string || `server.tls_key` |
191192
| `--tls-port` | int | `8443` | `server.tls_addr` (port part) |
@@ -205,6 +206,8 @@ Grouped by concern for readability. All flags are optional; unset flags do not o
205206
|------|------|---------|--------------|
206207
| `--no-cache` | bool | `false` | `cache.enabled = false` |
207208
| `--cache-size` | string | `256MB` | `cache.max_bytes` (parses `256MB`, `64MB`, `1GB`) |
209+
| `--preload` | bool | `false` | `cache.preload` — load all files into cache at startup |
210+
| `--gc-percent` | int | `0` | `cache.gc_percent` — Go GC target % (0 = default; try 400 for throughput) |
208211

209212
#### Compression
210213

@@ -244,6 +247,7 @@ static-web --dir-listing --no-dotfile-block ~/Downloads
244247

245248
# Serve with TLS (HTTPS on :443, HTTP redirect on :80)
246249
static-web --port 80 --tls-port 443 \
250+
--redirect-host static.example.com \
247251
--tls-cert /etc/ssl/cert.pem \
248252
--tls-key /etc/ssl/key.pem \
249253
./public
@@ -265,6 +269,9 @@ static-web
265269
# Disable caching (useful during local development to see file changes immediately)
266270
static-web --no-cache ./dist
267271

272+
# Maximum throughput: preload all files + tune GC
273+
static-web --preload --gc-percent 400 ./dist
274+
268275
# Print version info
269276
static-web version
270277
```
@@ -385,7 +392,7 @@ The CLI was implemented using Go stdlib `flag.FlagSet` — no external framework
385392
- **`--host` + `--port` merging**: `net.SplitHostPort` / `net.JoinHostPort` used to decompose and reconstruct `server.addr`.
386393
- **`parseBytes()`**: a small helper that parses `256MB`, `1GB`, etc. with `B`/`KB`/`MB`/`GB` suffixes (case-insensitive).
387394
- **`//go:embed config.toml.example`**: the example config is embedded in `cmd/static-web/` at compile time. The binary is fully self-contained.
388-
- **`--quiet`**: passes `io.Discard` to a `loggingMiddlewareWithWriter` variant, suppressing access log output with zero overhead.
395+
- **`--quiet`**: skips access-log middleware entirely, removing per-request logging overhead.
389396
- **`--verbose`**: calls `logConfig(cfg)` after all overrides are applied, so you see the final resolved values.
390397
- **Version injection**: `internal/version.Version`, `Commit`, `Date` are set via `-ldflags` at build time. Default to `"dev"`, `"none"`, `"unknown"` for `go run`.
391398

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build run test bench lint precompress clean release install commit bump changelog benchmark benchmark-keep benchmark-down
1+
.PHONY: build run test bench lint precompress clean release install commit bump changelog benchmark benchmark-keep benchmark-down benchmark-baremetal
22

33
# Binary output path and name
44
BIN := bin/static-web
@@ -83,3 +83,7 @@ benchmark-keep:
8383
## benchmark-down: tear down any running benchmark containers
8484
benchmark-down:
8585
docker compose -f benchmark/docker-compose.benchmark.yml down --remove-orphans
86+
87+
## benchmark-baremetal: run bare-metal benchmark (static-web production vs Bun, no Docker)
88+
benchmark-baremetal:
89+
@bash benchmark/baremetal.sh

0 commit comments

Comments
 (0)