Benchmark results
All benchmarks compare Velo against popular Go logging libraries. Lower is better.Logging 10 fields
Logging a message with 10 structured fields:| Package | Time | vs zap | Allocations |
|---|---|---|---|
| velo (fields) | 513 ns/op | -22% | 1 allocs/op |
| velo | 591 ns/op | -10% | 6 allocs/op |
| zap | 656 ns/op | baseline | 5 allocs/op |
| zap (sugared) | 856 ns/op | +30% | 10 allocs/op |
| apex/log | 1924 ns/op | +193% | 60 allocs/op |
| zerolog | 2144 ns/op | +227% | 38 allocs/op |
| slog | 2700 ns/op | +312% | 41 allocs/op |
| logrus | 3104 ns/op | +373% | 76 allocs/op |
Velo’s typed fields API is 22% faster than zap and uses only 1 allocation.
Logging with 10 context fields
Logging with pre-attached context fields (e.g., request ID, user ID):| Package | Time | vs zap | Allocations |
|---|---|---|---|
| zerolog | 18 ns/op | -73% | 0 allocs/op |
| velo (fields) | 55 ns/op | -18% | 0 allocs/op |
| velo | 57 ns/op | -15% | 0 allocs/op |
| zap | 67 ns/op | baseline | 0 allocs/op |
| zap (sugared) | 70 ns/op | +4% | 0 allocs/op |
| slog | 90 ns/op | +34% | 0 allocs/op |
| apex/log | 1924 ns/op | +2772% | 50 allocs/op |
| logrus | 2199 ns/op | +3182% | 65 allocs/op |
Logging a static string
Logging a simple message with no fields:| Package | Time | vs zap | Allocations |
|---|---|---|---|
| stdlib | 4 ns/op | -94% | 1 allocs/op |
| zerolog | 16 ns/op | -75% | 0 allocs/op |
| velo | 48 ns/op | -24% | 0 allocs/op |
| zap | 63 ns/op | baseline | 0 allocs/op |
| slog | 82 ns/op | +30% | 0 allocs/op |
| apex/log | 148 ns/op | +135% | 4 allocs/op |
| logrus | 272 ns/op | +332% | 20 allocs/op |
Performance optimization tips
1. Use typed fields
Typed fields eliminate interface boxing:- Slow (boxing overhead)
- Fast (zero allocations)
2. Enable async mode
Async mode moves I/O to a background worker:- Isolates application from I/O latency
- Parallelizes formatting and writing
- Reduces blocking in hot paths
- Must call
Close()to flush buffer - Requires memory for buffer
- Can apply backpressure under extreme load
3. Pre-encode context fields
Velo automatically pre-encodes fields when using JSON formatter:4. Set appropriate log levels
Filtering at the logger level is faster than filtering in aggregators:5. Avoid caller and stack traces in hot paths
Both features useruntime.Caller which is expensive:
6. Choose the right overflow strategy
Balance between log loss and latency:- OverflowSync (balanced)
- OverflowDrop (low latency)
- OverflowBlock (no loss)
7. Size your buffer appropriately
Buffer size affects memory usage and backpressure behavior:Buffer size must be a power of 2. Velo uses a lock-free ring buffer for maximum throughput.
8. Disable timestamps in log aggregators
If your log aggregator adds timestamps, disable them in Velo:9. Use JSON formatter in production
JSON is faster to parse in aggregators and more efficient to generate:Real-world performance example
Here’s a high-performance configuration for a production API:Performance checklist
Use this checklist to ensure optimal performance:Use typed fields in hot paths
Use typed fields in hot paths
✅ Replace
logger.Info(key, val) with logger.InfoFields(velo.Type(key, val))✅ Avoid Any() field type unless necessaryEnable async mode
Enable async mode
✅ Set
Async: true for production✅ Choose appropriate BufferSize (default 8192)✅ Always call defer logger.Close()Optimize formatters
Optimize formatters
✅ Use
JSONFormatter in production✅ Use TextFormatter in developmentPre-encode context fields
Pre-encode context fields
✅ Use
WithFields() for request-scoped loggers✅ Attach service metadata via Options.FieldsDisable expensive features
Disable expensive features
✅ Set
ReportCaller: false unless debugging✅ Set ReportStacktrace: false unless debugging errorsFilter at the source
Filter at the source
✅ Set appropriate
Level (e.g., InfoLevel in production)✅ Avoid logging in tight loopsProfiling your application
Use Go’s profiling tools to identify logging bottlenecks:velo.(*Logger).InfoFields- Hot path loggingruntime.Caller- Indicates caller reporting enabledruntime.Callers- Indicates stack trace capture
Next steps
Configuration
Learn all available configuration options
Typed fields
Master the typed fields API