Skip to content

Performance degradation with context pool after v0.3.0 #154

Open

Description

@adriantam

Our project are using context pool (with WithContext(), WithCancelOnError(), WithFirstError() and WithMaxGoroutines()). After upgrading from v0.3.0 to [5f936ab](https://github.com/sourcegraph/conc/commit/5f936abd7ae87036af1f75c95fb9d0daaf00116b), we have observed performance degradation (significant increase in CPU). The usually pattern involves pool.New(), pool.Go() and pool.Wait() with high concurrency.

Activity

  1. srabraham commented on Oct 21, 2025

    @srabraham

    @adriantam I will happily try to debug this. Could you please provide a sample piece of code that exhibits this behavior? This would be great in the form of a Benchmark test. https://pkg.go.dev/testing#hdr-Benchmarks

  2. srabraham commented on Dec 12, 2025

    @srabraham

    @adriantam this issue doesn't provide enough detail to be a useful bug report. Here's a benchmark test I made that satisfies the vague requirements in your original comment. The benchmark results on my machine are basically identical at HEAD versus at 1df97ec from Jan 2023. That's the farthest back we can go, because commits from before that won't build, due to a missing repository.

    // to be appended to pool/context_pool_test.go
    func BenchmarkContextPool(b *testing.B) {
    	for b.Loop() {
    		p := pool.New().WithContext(b.Context())
    		for i := 0; i < 1000; i++ {
    			p.Go(func(ctx context.Context) error {
    				for j := 0; j < 10000; j++ {
    					hasher := sha256.New()
    					hasher.Write([]byte(strconv.Itoa(i)))
    					_ = hasher.Sum(nil)
    				}
    				return nil
    			})
    		}
    		err := p.Wait()
    		if err != nil {
    			b.Fatal(err)
    		}
    	}
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions