Skip to content

v1.4.0 - Performance & Polish#10

Merged
vnykmshr merged 3 commits intomainfrom
feature/v1.4.0-performance-polish
Jan 19, 2026
Merged

v1.4.0 - Performance & Polish#10
vnykmshr merged 3 commits intomainfrom
feature/v1.4.0-performance-polish

Conversation

@vnykmshr
Copy link
Collaborator

Summary

Performance optimizations and code quality improvements for the goflow library. Non-breaking changes only.

  • Add comprehensive benchmark suite for performance visibility
  • Use atomic operations for pipeline stats to reduce lock contention
  • Code review feedback addressed

Changes

Phase 1: Benchmark Suite

  • Create internal/benchmark/ with comprehensive benchmarks
  • Add stream benchmarks (FromSlice, Filter, Map, ToSlice, Reduce, Distinct)
  • Add channel benchmarks (Send/Receive, contention, backpressure strategies)
  • Add workerpool benchmarks (submit/execute cycle, throughput, scaling)
  • Add make benchmark target

Phase 2: Atomic Pipeline Stats

  • Pipeline stats use sync/atomic for counters (TotalExecutions, SuccessfulRuns, FailedRuns, TotalDuration)
  • Mutex only for complex fields (LastExecutionAt, StageStats map)
  • Reduced lock contention under concurrent load

Phase 3: Code Cleanup

  • Audited nolint annotations - all necessary (interface implementations)
  • Verified error wrapping consistency - already correct (%w for errors)
  • No changes needed

Code Review Fix

  • Fixed label formatting functions to use strconv.Itoa for values >= 10

Benchmark Baseline (captured)

Operation ns/op B/op allocs/op
Stream/FromSlice-1k 92 112 2
Stream/Filter-1k 278,398 15,904 25
Channel/Send-100 1,078 303 5
Pipeline/Concurrent 1,042 440 6
WorkerPool/Submit-4w 1,557 247 2

Test Plan

  • All tests pass with -race flag
  • Lint passes with 0 issues
  • make benchmark produces comprehensive report
  • Code review feedback addressed

Checklist

  • Quality gates pass (lint, typecheck, test)
  • Atomic commits with clear messages
  • No breaking changes
  • All phases complete

Add benchmark suite covering stream, channel, and workerpool packages:
- Stream: FromSlice, Filter, Map, ChainedOps, ToSlice, ForEach, Reduce
- Channel: Send/Receive, contention levels, backpressure strategies
- WorkerPool: Submit, throughput, contention, scaling, shutdown

Add `make benchmark` target for comprehensive reporting.
Reduce lock contention in hot path by using atomic.Int64 for counters:
- totalExecutions, successfulRuns, failedRuns, totalDuration

Mutex now only protects complex data structures (lastExecutionAt, stageStats).
Stats() reads atomics lock-free, then briefly locks for map copy.

This improves throughput under concurrent pipeline execution.
- Fix contentionLabel in channel_bench_test.go to handle values >= 100
- Fix workerLabel in workerpool_bench_test.go to handle workers >= 10

The previous implementation used string(rune('0'+n)) which only works
for single-digit numbers. Using strconv.Itoa handles all integer values
correctly.
@vnykmshr
Copy link
Collaborator Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@vnykmshr vnykmshr merged commit c44340e into main Jan 19, 2026
4 checks passed
@vnykmshr vnykmshr deleted the feature/v1.4.0-performance-polish branch January 19, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments