# Mutex or channel in Go? Measured under contention

> We measured sync.Mutex and channels in Go 1.27 across three scenarios and different goroutine and P counts: which is faster depends on G and P.

- Kind: Infographic
- Published: 2026-10-03
- Based on: https://muhammetsafak.com/research/mutex-vs-channel-under-contention/
- Source: https://muhammetsafak.com/visuals/i/go-mutex-or-channel/
- Language: en-US
- Author: Muhammet Şafak

---
## Mutex or channel in Go?

Go · Concurrency · Measurement

Two ways to protect shared state, measured under contention in three scenarios. There is no short answer: the result changes with the number of goroutines (G) and P.

Muhammet Şafak October 3, 2026

## Measurement environment and confidence level

Context first

-   **Environment** Go 1.27.1 linux/arm64; Docker Engine 29.8.0, 12 vCPU, Apple M4 Pro. P values are vCPU groups separated with cpuset; the container has no network, is read-only, 4 GiB.
-   **Low confidence** 518 of 845 cells (61.3%) are flagged; the threshold is 15%. Speed and latency ratios come from unflagged cells; the one flagged cell cited in the visual is marked with its flag.
-   **Latency** Latency values are the upper bounds of logarithmic buckets, not exact measurements.

## Panel 3

5×

Scenario 1 · G=64, P=4

mutex p99 latency, versus the one-way channel

Mutex p99 is 491,519 ns, one-way channel 98,303 ns. In throughput the gap is 3.2% and within noise: 7.69 M versus 7.94 M ops/s.

## The picture flips as P grows

Scenario 1 · G=64, P=8

million ops/s

-   Mutex 15.96
-   One-way channel 6.65
-   Request-reply channel 3.97

Mutex is 2.40× faster than the one-way channel and 4.02× faster than the request-reply channel. From P=4 to P=8, mutex sped up 2.08×, while the channel dropped to 0.84×; the cause was not measured.

## Many goroutines: speed and fairness

Scenario 1 · G=10,000, P=8

Many goroutines: speed and fairness

| Method | Ops/s | Jain fairness index | Flag |
| --- | --- | --- | --- |
| Mutex | 14,878,958 | 0.8237 (not compared) | fairness\_unexplained |
| One-way channel | 2,052,681 (7.25× slower) | 0.9999 | none |
| Request-reply channel | 1,778,745 (8.36× slower) | 1.0000 | none |

## The mutex's unfairness could not be explained

Reading the fairness result

-   **Warning** The correct reading is not “mutex is less fair” but “the unfairness in the mutex cell cannot be explained.” The cell carries the fairness\_unexplained flag.
-   **Note** By the source's design rule, cells carrying this flag do not enter the fairness comparison across models. The mutex cell carries only the fairness flag; its speed ratio stands.

## Read-heavy load

Scenario 2 · G=64, P=4

Read-heavy load

| Read ratio | Mutex | Owner-goroutine channel | Difference |
| --- | --- | --- | --- |
| 50% | 9.86 M ops/s | 4.42 M ops/s | Mutex 2.23× faster |
| 90% | 12.23 M ops/s | 4.58 M ops/s | Mutex 2.67× faster |

## Producer-consumer queue

Scenario 3 · G=64, P=4

million ops/s

-   Channel with buffer 1 6.91
-   Unbuffered channel 5.41
-   Queue with sync.Cond (buffer 1,024) 4.46

The channel with buffer 1 is 1.28× faster than the unbuffered one and 1.55× faster than the sync.Cond queue. The channel cells with buffers 64 and 1,024 are flagged and left out.

## What we did not claim

Flagged cells

-   **Scenario 1** The P=1 and P=2 cells are flagged; no result is stated for those P values.
-   **Scenario 2** The 99% read cell is flagged, so no ratio is given. The RWMutex cells carry the observer\_effect flag.
-   **Flags** fairness\_unexplained 235, spread\_p99 189, observer\_effect 171, spread\_throughput 125, calib\_drift 72, spread\_persistent 36.

## What this measurement does not tell you

Limits

-   **Warning** The load is a synthetic counter, not a production workload.
-   **Note** sync.Map was not measured.
-   **Note** P values are vCPUs inside a virtual machine; they are not physical cores.
-   **Note** The causes of the differences were not measured; the visual only shows what happened.

## Panel 11

Conclusion

The answer to “which is faster?” depends on G and P.

This record does not say which is faster, but when each is faster. Don't assume a behavior in production when you don't know its cause; measure on your own P.
