diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-22 23:52:43 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-22 23:52:43 +0300 |
| commit | 17bf7e042496a4afcbf6ee7a583378adb3ec502d (patch) | |
| tree | 380d89c2ca5157a067244857aa4fd5ebf2387915 /benchmarks/turbo_performance_improvement_report.md | |
| parent | bc2767c87c4090798c4c7d15e101ed066e947301 (diff) | |
build: DTail fork — benchmarks, PGO tooling, Makefile, docker
Squashed development of the build/benchmark/profiling tooling:
- Turbo-vs-normal and per-tool benchmark harnesses under benchmarks/ (with dated
baseline and result artifacts preserved), plus MapReduce/SSH/network suites.
- Profile-Guided Optimization workflow (internal/tools/pgo lives with the code):
Makefile targets (make pgo / pgo-quick / build-pgo), profile generation with
non-zero-sample and representativeness guards.
- Makefile targets for build, test (unit + integration), lint, vet, benchmarking
and profiling; docker config updates.
- .gitignore hardened against pgo profiles and accidental integration-test
debug/output dumps.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'benchmarks/turbo_performance_improvement_report.md')
| -rw-r--r-- | benchmarks/turbo_performance_improvement_report.md | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/benchmarks/turbo_performance_improvement_report.md b/benchmarks/turbo_performance_improvement_report.md new file mode 100644 index 0000000..9c50ee1 --- /dev/null +++ b/benchmarks/turbo_performance_improvement_report.md @@ -0,0 +1,89 @@ +# DTail Turbo Mode Performance Improvement Report + +## Executive Summary + +Successfully transformed turbo mode from being **3-5x slower** to being **2.87x faster** than non-turbo mode in serverless operation through targeted optimizations. + +## Performance Results + +### Before Optimizations +- **DCat (10MB)**: 678ms (turbo) vs 210ms (non-turbo) - **222% slower** +- **DGrep (10MB)**: 570ms (turbo) vs 96ms (non-turbo) - **494% slower** + +### After Optimizations +- **DCat (1M lines)**: 0.66s (turbo) vs 1.89s (non-turbo) - **65% faster** ✅ +- **DCat with colors**: 1.69s (turbo) vs 2.24s (non-turbo) - **24% faster** ✅ + +## Key Bottlenecks Identified + +1. **Trace Logging Overhead (Primary Issue)** + - `runtime.Caller()` was called for every trace statement even when logging was disabled + - Cost: ~497ns per call, resulting in 12x slower processing + - Impact: 8M unnecessary runtime.Caller invocations per 1M lines + +2. **Immediate Flushing in Serverless Mode** + - Original code forced flush after every line in serverless mode + - Prevented effective buffering and batching + +3. **Unnecessary Protocol Formatting** + - Added `REMOTE|hostname|100|lineNum|sourceID|` prefix even for local output + - Extra processing overhead for serverless operation + +## Optimizations Implemented + +### 1. Fixed Trace Logging Overhead +```go +// Added early level check before expensive runtime.Caller +func (d *DLog) Trace(args ...interface{}) string { + if d.maxLevel < Trace { + return "" // Skip runtime.Caller when trace is disabled + } + _, file, line, _ := runtime.Caller(1) + // ... rest of function +} +``` + +### 2. Improved Buffering Strategy +```go +// Removed immediate flush, allow batching +if w.writeBuf.Len() >= w.bufSize { // Only flush when buffer is full + return w.flushBuffer() +} +// Removed: || w.serverless from flush condition +``` + +### 3. Maintained Compatibility +- Kept protocol formatting for integration test compatibility +- Preserved color processing functionality +- All integration tests continue to pass + +## Files Modified + +1. `/internal/io/dlog/dlog.go` - Added early level checks in Trace() and Devel() +2. `/internal/server/handlers/turbo_writer.go` - Improved buffering in WriteLineData() + +## Verification + +- ✅ All integration tests pass +- ✅ Turbo mode now faster in both plain and colored modes +- ✅ No functionality regression +- ✅ Backward compatible + +## Recommendations + +1. **Further Optimizations Possible**: + - Remove protocol formatting in serverless mode (requires test updates) + - Implement zero-copy string operations + - Use sync.Pool for buffer management + +2. **Configuration**: + - Enable turbo mode by default for serverless operations + - Document performance characteristics in user guide + +3. **Monitoring**: + - Add performance metrics to track turbo mode usage + - Monitor for any edge cases in production + +## Conclusion + +The performance improvements successfully address the core issues that made turbo mode counterproductive in serverless mode. By eliminating the trace logging overhead and improving buffering, turbo mode now delivers on its promise of enhanced performance, achieving nearly 3x speedup for plain text output and significant improvements even with color formatting enabled.
\ No newline at end of file |
