Skip to content

Commit 33efd93

Browse files
nits
1 parent 5afe961 commit 33efd93

4 files changed

Lines changed: 12 additions & 13 deletions

File tree

content/learning-paths/servers-and-cloud-computing/go-gc-default-settings/create_gc_benchmark.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func BenchmarkParseAndAllocate(b *testing.B) {
6464
b.ReportAllocs()
6565
6666
/*
67-
Captures runtime memory statistics before the benchmark starts. You'll later compare these values to see:
67+
Captures runtime memory statistics before the benchmark starts. You'll later compare these values to see:
6868
- how many GCs occurred
6969
- how much pause time was spent in GC
7070
*/
@@ -77,8 +77,8 @@ func BenchmarkParseAndAllocate(b *testing.B) {
7777
b.ResetTimer()
7878
7979
/*
80-
Benchmark loop where the actual work is done. The number of times this loop is
81-
executed is controlled by the b.N variable. The value of b.N is automatically chosen by the Go benchmark framework to obtain stable and statistically useful measurements.
80+
Benchmark loop where the actual work is done. The number of times this loop is
81+
executed is controlled by the b.N variable. The value of b.N is automatically chosen by the Go benchmark framework to obtain stable and statistically useful measurements.
8282
8383
The reason for this design is that timing a single operation is often unreliable. Running it many times reduces noise from:
8484
- OS scheduling
@@ -90,7 +90,7 @@ func BenchmarkParseAndAllocate(b *testing.B) {
9090
// splits the large payload into individual records.
9191
// Example: "a=1;b=2;c=3;" becomes: ["a=1", "b=2", "c=3", ""]
9292
parts := strings.Split(payload, ";")
93-
// Creates a new slice to store parsed output. This allocation is intentional for the benchmark to generate memory pressure and trigger GC activity.
93+
// Creates a new slice to store parsed output. This allocation is intentional for the benchmark to generate memory pressure and trigger GC activity.
9494
9595
out := make([]string, 0, len(parts))
9696

content/learning-paths/servers-and-cloud-computing/go-gc-default-settings/interpret_gc_results.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Look for functions that dominate CPU time. In an allocation-heavy benchmark, you
4040

4141
The `flat` column shows CPU time spent directly in that function. The `cum` (cumulative) column includes time spent in the function and all functions it called. A function with low `flat` but high `cum` is spending most of its time in callees, which can point to allocation chains or deep call stacks.
4242

43-
On the validated `m8g.xlarge` instance, the top CPU profile entries included string scanning, string concatenation, split handling, and allocation paths:
43+
On the validated `m8g.xlarge` instance, the top CPU profile entries include string scanning, string concatenation, split handling, and allocation paths:
4444

4545
```text
4646
flat flat% sum% cum cum%
@@ -61,7 +61,7 @@ cat mem_default_alloc_top.txt
6161

6262
Reducing allocation volume in those functions usually gives the Go garbage collector less work to do.
6363

64-
On the validated `m8g.xlarge` instance, the allocation profile showed that `strings.genSplit` and the benchmark function accounted for nearly all allocated bytes:
64+
On the validated `m8g.xlarge` instance, the allocation profile shows that `strings.genSplit` and the benchmark function account for nearly all allocated bytes:
6565

6666
```text
6767
flat flat% sum% cum cum%

content/learning-paths/servers-and-cloud-computing/go-gc-default-settings/run_default_gc_benchmark.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ BenchmarkParseAndAllocate-4 66757 179173 ns/op
153153
PASS
154154
```
155155

156-
Inspect the CPU profile to display the functions that consumed the most CPU time during benchmark execution, ranked from highest to lowest:
156+
Inspect the CPU profile to list the functions that consumed the most CPU time during benchmark execution, ranked from highest to lowest:
157157

158158
```bash
159159
go tool pprof -top ./parsebench.test cpu_default.out | tee cpu_default_top.txt
@@ -177,7 +177,7 @@ Dropped 162 nodes (cum <= 0.08s)
177177
0.80s 5.08% 47.84% 2.71s 17.22% runtime.mallocgcSmallScanNoHeader
178178
```
179179

180-
Inspect the heap allocation profile to display the functions responsible for allocating the most total memory over the lifetime of the benchmark, ranked from highest to lowest:
180+
Inspect the heap allocation profile to list the functions responsible for allocating the most total memory over the lifetime of the benchmark, ranked from highest to lowest:
181181

182182
```bash
183183
go tool pprof -top -alloc_space ./parsebench.test mem_default.out | tee mem_default_alloc_top.txt
@@ -205,7 +205,7 @@ Dropped 37 nodes (cum <= 0.06GB)
205205

206206
You've now captured a default-GC benchmark result, a Benchstat summary, and CPU and heap profiles from the same workload.
207207

208-
Next, you'll analyze all of these results.
208+
Next, you'll analyze the benchmark results.
209209

210210

211211

content/learning-paths/servers-and-cloud-computing/go-gc-default-settings/try_on_your_own.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ParseAndAllocate-4 160.0Ki ± 0% 80.0Ki ± 0% -50.00% (p=0.000)
4040

4141
Assume that the payload size this benchmark is intended to represent is only 512 records instead of 2048.
4242

43-
To test whether a smaller workload affects GC frequency, pause times, and overall application performance, you can reduce the payload size from the following:
43+
To test whether a smaller workload affects GC frequency, pause times, and overall application performance, reduce the payload size from the following:
4444

4545
```go
4646
payload := strings.Repeat(
@@ -64,7 +64,7 @@ Reducing the payload size creates fewer temporary objects and less garbage each
6464

6565
Assume that after profiling the application, you discover that the input payload rarely changes between requests.
6666

67-
To reuse preprocessing work and determine whether reducing repeated allocations improves GC behavior and throughput, you can update split logic from the following:
67+
To reuse preprocessing work, update split logic from the following:
6868

6969
```go
7070
for i := 0; i < b.N; i++ {
@@ -88,7 +88,7 @@ for i := 0; i < b.N; i++ {
8888
}
8989
```
9090

91-
By making this change, you can avoid repeatedly allocating the same slice of records on every iteration. Reducing repeated allocations improves GC behavior and throughput.
91+
By making this change, you can avoid repeatedly allocating the same slice of records on every iteration. Reducing repeated allocations improves GC behavior and throughput.
9292

9393
### Reuse the output slice
9494

@@ -118,7 +118,6 @@ for i := 0; i < b.N; i++ {
118118

119119
By modifying the benchmark to reuse the backing array, you can reduce allocations and GC pressure.
120120

121-
122121
### Replace SplitN() with IndexByte()
123122

124123
Assume a CPU profile shows that string parsing is one of the hottest code paths in the application.

0 commit comments

Comments
 (0)