Commit cea7d2e
Combine: Optimize for all nil (#55)
The current implementation of Combine returns the input slice in the
returned multierr. This causes it to escape to the heap unconditionally.
Optimizing for the no-errors case, we can copy the slice in that case
and keep it on the stack.
```
name old time/op new time/op delta
Combine/inline_1-8 17.7ns ± 0% 2.1ns ± 0% -88.20% (p=0.008 n=5+5)
Combine/inline_2-8 21.0ns ± 0% 4.4ns ± 1% -79.03% (p=0.008 n=5+5)
Combine/inline_3_no_error-8 24.4ns ± 0% 5.1ns ± 1% -79.22% (p=0.016 n=4+5)
Combine/inline_3_one_error-8 24.8ns ± 0% 5.4ns ± 1% -78.42% (p=0.008 n=5+5)
Combine/inline_3_multiple_errors-8 44.3ns ± 0% 54.9ns ± 0% +23.80% (p=0.008 n=5+5)
Combine/slice_100_no_errors-8 72.9ns ± 0% 73.4ns ± 1% +0.68% (p=0.008 n=5+5)
Combine/slice_100_one_error-8 74.5ns ± 0% 74.8ns ± 0% ~ (p=0.056 n=5+5)
Combine/slice_100_multi_error-8 193ns ± 0% 193ns ± 0% ~ (p=0.127 n=5+5)
name old alloc/op new alloc/op delta
Combine/inline_1-8 16.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5)
Combine/inline_2-8 32.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5)
Combine/inline_3_no_error-8 48.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5)
Combine/inline_3_one_error-8 48.0B ± 0% 0.0B -100.00% (p=0.008 n=5+5)
Combine/inline_3_multiple_errors-8 80.0B ± 0% 80.0B ± 0% ~ (all equal)
Combine/slice_100_no_errors-8 0.00B 0.00B ~ (all equal)
Combine/slice_100_one_error-8 0.00B 0.00B ~ (all equal)
Combine/slice_100_multi_error-8 64.0B ± 0% 64.0B ± 0% ~ (all equal)
name old allocs/op new allocs/op delta
Combine/inline_1-8 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5)
Combine/inline_2-8 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5)
Combine/inline_3_no_error-8 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5)
Combine/inline_3_one_error-8 1.00 ± 0% 0.00 -100.00% (p=0.008 n=5+5)
Combine/inline_3_multiple_errors-8 2.00 ± 0% 2.00 ± 0% ~ (all equal)
Combine/slice_100_no_errors-8 0.00 0.00 ~ (all equal)
Combine/slice_100_one_error-8 0.00 0.00 ~ (all equal)
Combine/slice_100_multi_error-8 2.00 ± 0% 2.00 ± 0% ~ (all equal)
```
Co-authored-by: Abhinav Gupta <abg@uber.com>1 parent d49c2ba commit cea7d2e
3 files changed
+94
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
375 | 383 | | |
376 | 384 | | |
377 | 385 | | |
| |||
381 | 389 | | |
382 | 390 | | |
383 | 391 | | |
384 | | - | |
385 | | - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
386 | 399 | | |
387 | 400 | | |
388 | 401 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
100 | 106 | | |
101 | 107 | | |
102 | 108 | | |
| |||
273 | 279 | | |
274 | 280 | | |
275 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
276 | 290 | | |
277 | 291 | | |
278 | 292 | | |
| |||
0 commit comments