Skip to content

Commit 0a469d5

Browse files
committed
update benchmarks
1 parent 50fe0e2 commit 0a469d5

File tree

10 files changed

+43
-34
lines changed

10 files changed

+43
-34
lines changed

10_concurrently.png

21.4 KB
Loading

README.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,43 @@ func main() {
5656

5757
## Comparison to others
5858

59-
[dataloaden](https://github.com/vektah/dataloaden) uses code generation and has similar performance
60-
[dataloader](https://github.com/graph-gophers/dataloader) does not use code generation but has much worse performance and is more difficult to use
59+
* [dataloaden](https://github.com/vektah/dataloaden) uses code generation and has similar performance
60+
* [dataloader](https://github.com/graph-gophers/dataloader) does not use code generation but has much worse performance and is more difficult to use
61+
* [yckao/go-dataloader](https://github.com/yckao/go-dataloader) does not use code generation but has much worse performance and is very similar to dataloader.
6162

62-
Benchmarks show that this package is faster than both of the above and I find it easier to use.
63+
The benchmarks in this repo show that this package is faster than all of the above and I also find it easier to use.
6364

65+
<details>
66+
<summary>Benchmark data as CSV</summary>
6467
```
65-
BenchmarkDataloader/caches-8 4363897 273.6 ns/op 168 B/op 5 allocs/op
66-
BenchmarkDataloader/random_spread-8 1000000 1308 ns/op 620 B/op 11 allocs/op
67-
BenchmarkDataloader/10_concurently-8 15818 80064 ns/op 29203 B/op 155 allocs/op
68-
BenchmarkDataloader/all_in_one_request-8 10000 6886305 ns/op 2575523 B/op 60026 allocs/op
69-
70-
BenchmarkDataloaden/caches-8 19571458 60.74 ns/op 24 B/op 1 allocs/op
71-
BenchmarkDataloaden/random_spread-8 2477028 653.7 ns/op 302 B/op 5 allocs/op
72-
BenchmarkDataloaden/10_concurently-8 20932 53285 ns/op 2802 B/op 75 allocs/op
73-
BenchmarkDataloaden/all_in_one_request-8 10000 1303027 ns/op 487867 B/op 10007 allocs/op
74-
75-
BenchmarkDataloadgen/caches-8 22270087 53.23 ns/op 8 B/op 0 allocs/op
76-
BenchmarkDataloadgen/random_spread-8 2454928 495.9 ns/op 289 B/op 4 allocs/op
77-
BenchmarkDataloadgen/10_concurently-8 17260 65339 ns/op 9541 B/op 63 allocs/op
78-
BenchmarkDataloadgen/all_in_one_request-8 10000 978196 ns/op 573651 B/op 8 allocs/op
68+
Benchmark,Package,iterations,ns/op,B/op,allocs/op
69+
init-8,graph-gophers/dataloader,"9,242,047.00",130.50,208.00,3.00
70+
init-8,vektah/dataloaden,"1,000,000,000.00",0.27,0.00,0.00
71+
init-8,yckao/go-dataloader,"3,153,999.00",402.10,400.00,10.00
72+
init-8,vikstrous/dataloadgen,"10,347,595.00",114.90,128.00,3.00
73+
cached-8,graph-gophers/dataloader,"4,669.00","222,072.00","25,307.00",522.00
74+
cached-8,vektah/dataloaden,"1,243.00","1,037,044.00","5,234.00",110.00
75+
cached-8,yckao/go-dataloader,"2,312.00","580,860.00","2,273.00",130.00
76+
cached-8,vikstrous/dataloadgen,"1,552.00","824,939.00",776.00,15.00
77+
unique_keys-8,graph-gophers/dataloader,"12,334.00","97,118.00","56,314.00",945.00
78+
unique_keys-8,vektah/dataloaden,"36,489.00","32,507.00","37,514.00",227.00
79+
unique_keys-8,yckao/go-dataloader,"8,055.00","133,224.00","50,180.00",747.00
80+
unique_keys-8,vikstrous/dataloadgen,"42,943.00","27,257.00","22,255.00",230.00
81+
10_concurrently-8,graph-gophers/dataloader,326.00,"11,119,367.00","5,574,460.00","164,247.00"
82+
10_concurrently-8,vektah/dataloaden,100.00,"194,627,574.00","898,977.00","19,502.00"
83+
10_concurrently-8,yckao/go-dataloader,278.00,"10,972,399.00","314,963.00","29,558.00"
84+
10_concurrently-8,vikstrous/dataloadgen,643.00,"8,249,158.00","43,474.00",806.00
85+
all_in_one_request-8,graph-gophers/dataloader,28.00,"39,954,324.00","27,475,136.00","158,321.00"
86+
all_in_one_request-8,vektah/dataloaden,328.00,"3,713,407.00","3,533,086.00","41,368.00"
87+
all_in_one_request-8,yckao/go-dataloader,132.00,"9,060,571.00","4,886,722.00","102,564.00"
88+
all_in_one_request-8,vikstrous/dataloadgen,375.00,"3,206,175.00","2,518,498.00","41,582.00"
7989
```
90+
</details>
8091

81-
To run the benchmarks, run `go test -bench=. . -benchmem` from the benchmark directory.
92+
![](init.png)
93+
![](cached.png)
94+
![](unique_keys.png)
95+
![](10_concurrently.png)
96+
![](all_in_one_request.png)
97+
98+
To run the benchmarks, run `go test -bench=. . -run BenchmarkAll -benchmem` from the benchmark directory.

all_in_one_request.png

21.6 KB
Loading

benchmark/benchmarks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func BenchmarkAll(b *testing.B) {
222222
}
223223
})
224224
})
225-
b.Run("10 concurently", func(b *testing.B) {
225+
b.Run("10 concurrently", func(b *testing.B) {
226226
b.Run("dataloader", func(b *testing.B) {
227227
for n := 0; n < b.N*10; n++ {
228228
dataloaderDL := newDataloader()

benchmark/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ require (
1515
go.opentelemetry.io/otel/trace v1.11.1 // indirect
1616
golang.org/x/tools v0.0.0-20190515012406-7d7faa4812bd // indirect
1717
)
18+
19+
replace github.com/vikstrous/dataloadgen => ../

caches.png

18.2 KB
Loading

dataloader_test.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ func BenchmarkLoaderFromDataloader(b *testing.B) {
1919
dl := dataloadgen.NewLoader(func(_ context.Context, keys []string) (results []string, errs []error) {
2020
a.Add(len(keys))
2121
results = make([]string, 0, len(keys))
22-
for _, key := range keys {
23-
results = append(results, key)
24-
}
22+
results = append(results, keys...)
2523
return results, nil
2624
})
2725
b.ResetTimer()
@@ -221,11 +219,9 @@ func TestLoader(t *testing.T) {
221219

222220
n := 10
223221
reqs := []func() (string, error){}
224-
keys := []string{}
225222
for i := 0; i < n; i++ {
226223
key := strconv.Itoa(i)
227224
reqs = append(reqs, faultyLoader.LoadThunk(ctx, key))
228-
keys = append(keys, key)
229225
}
230226

231227
for _, future := range reqs {
@@ -489,9 +485,7 @@ func IDLoader(max int) (*dataloadgen.Loader[string, string], *[][]string) {
489485
mu.Lock()
490486
loadCalls = append(loadCalls, keys)
491487
mu.Unlock()
492-
for _, key := range keys {
493-
results = append(results, key)
494-
}
488+
results = append(results, keys...)
495489
return results, nil
496490
}, dataloadgen.WithBatchCapacity(max))
497491
return identityLoader, &loadCalls
@@ -504,9 +498,7 @@ func BatchOnlyLoader(max int) (*dataloadgen.Loader[string, string], *[][]string)
504498
mu.Lock()
505499
loadCalls = append(loadCalls, keys)
506500
mu.Unlock()
507-
for _, key := range keys {
508-
results = append(results, key)
509-
}
501+
results = append(results, keys...)
510502
return results, nil
511503
}, dataloadgen.WithBatchCapacity(max)) // dataloadgen.WithClearCacheOnBatch())
512504
return identityLoader, &loadCalls
@@ -579,9 +571,7 @@ func NoCacheLoader(max int) (*dataloadgen.Loader[string, string], *[][]string) {
579571
mu.Lock()
580572
loadCalls = append(loadCalls, keys)
581573
mu.Unlock()
582-
for _, key := range keys {
583-
results = append(results, key)
584-
}
574+
results = append(results, keys...)
585575
return results, nil
586576
}, /*dataloadgen.WithCache(cache),*/ dataloadgen.WithBatchCapacity(max))
587577
return identityLoader, &loadCalls

dataloadgen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (l *Loader[KeyT, ValueT]) LoadAllThunk(ctx context.Context, keys []KeyT) fu
200200
allNil := true
201201
for i, thunk := range thunks {
202202
values[i], errors[i] = thunk()
203-
if allNil == true && errors[i] != nil {
203+
if allNil && errors[i] != nil {
204204
allNil = false
205205
}
206206
}

init.png

11.9 KB
Loading

unique_keys.png

20.3 KB
Loading

0 commit comments

Comments
 (0)