High-performance, event-driven WebSocket library for Go β‘
BlazeWave is a modern, production-ready WebSocket library inspired by and improved from nhooyr/websocket. It provides blazing-fast performance with high-performance operations, smart buffer pooling, and comprehensive event handling.
- π Industry-Leading Performance: 3.8Γ throughput increase, 2.7Γ latency optimization
- β‘ High-Performance Architecture: Industry-leading high-performance WebSocket library
- π― Event-Driven: Comprehensive event system with middleware support
- π‘οΈ Production Ready: RFC 6455 compliant, compression support, robust error handling
- π§ Developer Friendly: Simple API, type safety, extensive testing (65.3% coverage)
- π Cross Platform: Support for Go 1.21+ on all major platforms including WASM
Test Environment: Apple M1 Max (10-core), 32GB RAM, Go 1.24.5 darwin/arm64
π Performance Metrics
| Metric | Value | Unit |
|---|---|---|
| Throughput | 82,650 | ops/sec (35.23 MB/s) |
| Latency | 13,887 | ns/op (13.9 ΞΌs) |
| Memory | 327 | B/op (16 allocs/op) |
| Efficiency | 99.2% | (vs baseline) |
| Metric | Standard | Zero-Copy Read/Write & Zero-GC | Improvement | Multiplier |
|---|---|---|---|---|
| Throughput | 37,077 ops/sec | 82,650 ops/sec | +123% β‘ | 2.23Γ |
| Latency | 32,381 ns | 13,887 ns | -57% β‘ | 2.33Γ |
| Memory | 742 B/op | 327 B/op | -56% β‘ | 2.27Γ |
| Allocations | 32 allocs/op | 16 allocs/op | -50% β‘ | 2.00Γ |
| Library | Zero-Copy Read/Write & Zero-GC | Buffer Pooling | Event-Driven |
|---|---|---|---|
| BlazeWave | β Native Support | β Smart Pooling | β Comprehensive Events |
| nhooyr/websocket | β None | β None | β None |
| gorilla/websocket | β None | β None | β Basic Events |
| fasthttp/websocket | β None | β None | β Basic Events |
π BlazeWave Core Advantages
| Feature | Description | Advantage |
|---|---|---|
| β‘ Zero-Copy Read/Write & Zero-GC | Zero Memory Copy, Zero GC Pressure | Ultimate Performance |
| π Smart Buffer Pooling | Cross-connection Memory Reuse, Reduced GC | Memory Efficiency |
| π― Comprehensive Event System | Middleware & Custom Events, Beyond Basic | Developer Experience |
| π‘οΈ Production Ready | RFC 6455 Compliant, Robust Error Handling | Enterprise Stability |
| π§ Developer Friendly | Simple API, Type Safety, Extensive Testing | Quick Start |
go get github.com/heyehang/blazewaveBlazeWave's high-performance design eliminates unnecessary memory allocations:
- Direct Buffer Access: High-frequency read/write operations bypass intermediate buffers
- Memory Pool Reuse: Smart buffer pooling reduces GC pressure
- Buffer Pooling: Reusable buffers across connections
- Timer Pooling: Reusable timers across connections
- GC-Friendly: Reduced garbage collection overhead
- High Performance Processing: Optimized message handling pipeline
- Sustained I/O: Efficient network I/O processing
- Concurrency Optimization: Buffer pool and timer optimization
Note: The following examples demonstrate standard mode usage. For zero-copy read/write & zero-GC mode advanced usage, please refer to BlazeWave Pulse or check local examples or unit tests.
π‘ Tip: Zero-copy read/write & zero-GC mode is achieved by using optimized buffer pools and shared timer pools, suitable for production environments.
package main
import (
"context"
"log"
"net/http"
"github.com/heyehang/blazewave"
// "github.com/heyehang/blazewave/core/pool" // Required for zero-copy read/write & zero-GC mode
// "github.com/heyehang/blazewave/core/timer" // Required for shared timer pool
)
func main() {
// Standard mode: use default configuration
server := blazewave.NewServer()
// Zero-copy read/write & zero-GC mode: use custom buffer pools and shared timer pool
// rPool := pool.NewPool(64, 4*1024)
// wPool := pool.NewPool(64, 4*1024)
// sharedTimer := timer.NewTimer(100) // Shared timer pool with capacity 100
// server := blazewave.NewServer(
// blazewave.WithServerReaderPool(rPool),
// blazewave.WithServerWriterPool(wPool),
// blazewave.WithServerHeartbeatTimer(sharedTimer),
// )
server.OnTextMessage(func(ctx context.Context, conn *blazewave.Conn, payload []byte) error {
log.Printf("Received: %s", string(payload))
return conn.Write(ctx, blazewave.MessageText, payload)
})
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
conn, err := server.Accept(w, r)
if err != nil {
log.Printf("Accept failed: %v", err)
return
}
defer conn.Close(blazewave.StatusNormalClosure, "")
})
log.Fatal(http.ListenAndServe(":8080", nil))
}package main
import (
"context"
"log"
"time"
"github.com/heyehang/blazewave"
// "github.com/heyehang/blazewave/core/pool" // Required for zero-copy read/write & zero-GC mode
// "github.com/heyehang/blazewave/core/timer" // Required for shared timer pool
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Standard mode: use default configuration
client := blazewave.NewClient()
// Zero-copy read/write & zero-GC mode: use custom buffer pools and shared timer pool
// rPool := pool.NewPool(64, 4*1024)
// wPool := pool.NewPool(64, 4*1024)
// sharedTimer := timer.NewTimer(100) // Shared timer pool with capacity 100
// client := blazewave.NewClient(
// blazewave.WithClientReaderPool(rPool),
// blazewave.WithClientWriterPool(wPool),
// blazewave.WithClientHeartbeatTimer(sharedTimer),
// )
// Register event handlers
client.OnConnect(func(ctx context.Context, conn *blazewave.Conn) error {
log.Println("Connected to server!")
return nil
})
client.OnTextMessage(func(ctx context.Context, conn *blazewave.Conn, payload []byte) error {
log.Printf("Received message: %s", string(payload))
return nil
})
client.OnDisconnect(func(ctx context.Context, conn *blazewave.Conn) error {
log.Println("Disconnected from server")
return nil
})
// Connect to server
conn, _, err := client.Dial(ctx, "ws://localhost:8080/ws", nil)
if err != nil {
log.Fatal("Dial failed:", err)
}
defer conn.Close(blazewave.StatusNormalClosure, "")
// Send message
err = conn.Write(ctx, blazewave.MessageText, []byte("Hello, BlazeWave!"))
if err != nil {
log.Fatal("Write failed:", err)
}
// Keep connection alive for a while
time.Sleep(5 * time.Second)
}ποΈ BlazeWave Architecture Design
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BlazeWave Core Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββ β
β β Application β β Connection β β Processing β β
β β β’ Event System βββββΊβ β’ Zero-Copy I/O βββββΊβ β’ Frame Parsing β β
β β β’ Middleware β β β’ Buffer Pool β β β’ Mask Processingβ β
β β β’ Heartbeat β β β’ Compression β β β’ Validation β β
β βββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββ β
β β β β β
β βΌ βΌ βΌ β
β βββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββ β
β β Infrastructure β β Optimization β β Network Layer β β
β β β’ Buffer Pool β β β’ Zero-Copy β β β’ TCP/WebSocket β β
β β β’ Memory Reuse β β β’ Zero-GC β β β’ TLS Support β β
β β β’ GC Optimized β β β’ Event-Driven β β β’ Hijacking β β
β βββββββββββββββββββ βββββββββββββββββββ ββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Performance Optimization Notes:
- Buffer Pool Reuse: Shared buffers across connections, reducing high-frequency memory allocations and GC pressure
- Timer Pool Reuse: Use
WithServerHeartbeatTimer()andWithClientHeartbeatTimer()to share timer pools - Zero-Copy Read/Write & Zero-GC Optimization: Use optimized buffer pools and shared timer pools
BlazeWave is designed around the core philosophy of event-driven real-time applications. For the best implementation examples and production-ready patterns, check out our reference project:
BlazeWave Pulse β‘
The definitive reference implementation showcasing BlazeWave's core concepts
- Real-time Collaboration: Multi-user interactive applications
- Event-Driven Architecture: Complete event system implementation
- Production Patterns: Scalable, maintainable code structure
- Performance Optimization: High-performance, buffer pooling
This project demonstrates the best practices for building high-performance, real-time applications with BlazeWave.
Check out our interactive examples:
- Chat Demo: Real-time chat application with user management

- Shared Mascot: Collaborative mascot movement demo

- More Examples: Complete list of available demos
- Inspired by and improved from nhooyr/websocket
- Built with Go's excellent standard library