Skip to content

Commit de3c035

Browse files
committed
performance boost explanation
1 parent c6ee08a commit de3c035

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ testv:
4545
test:
4646
$(GO) test $(TEST_ARGS) $(PKGS)
4747

48+
inline_err2:
49+
$(GO) test -c -gcflags=-m=2 $(PKG_ERR2) 2>&1 | ag 'inlin'
50+
51+
tinline_err2:
52+
$(GO) test -c -gcflags=-m=2 $(PKG_ERR2) 2>&1 | ag 'inlin' | ag 'err2_test'
53+
54+
inline_handler:
55+
$(GO) test -c -gcflags=-m=2 $(PKG_HANDLER) 2>&1 | ag 'inlin'
56+
57+
tinline_handler:
58+
$(GO) test -c -gcflags=-m=2 $(PKG_HANDLER) 2>&1 | ag 'inlin'
59+
4860
bench:
4961
$(GO) test -bench=. $(PKGS)
5062

@@ -69,6 +81,9 @@ bench_that:
6981
bench_copy:
7082
$(GO) test -bench='Benchmark_CopyBuffer' $(PKG_TRY)
7183

84+
bench_rece:
85+
$(GO) test -bench='BenchmarkRecursionWithTryAnd_Empty_Defer' $(PKG_ERR2)
86+
7287
bench_rec:
7388
$(GO) test -bench='BenchmarkRecursionWithOldErrorIfCheckAnd_Defer' $(PKG_ERR2)
7489

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,11 @@ Please see the full version history from [CHANGELOG](./CHANGELOG.md).
431431
432432
##### 0.9.40
433433
- Huge performance boost for: `defer err2.Handle/Catch()`
434-
- **3x faster happy path**, tested 100 deep call stack with every lvl has `defer`
435-
- solution caused change to API (core reason is Go's optimization "bug")
434+
- **3x faster happy path than the previous version, which is now equal to
435+
simplest `defer` function in the err-returning function** . (Please see the
436+
`defer` benchmarks in the `err2_test.go` and run `make bench_reca`)
437+
- the solution caused a change to API, where the core reason is Go's
438+
optimization "bug". (We don't have confirmation yet)
436439
- Changed API for deferred error handling: `defer err2.Handle/Catch()`
437440
- deprecated:
438441
```go

samples/main-nil.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func Init() {
3030
}
3131

3232
func doMainAll() {
33+
Init()
34+
3335
logger.Info("=== 1. preferred successful status output ===")
3436
doMain1()
3537
logger.Info("=== 2. NilThen and try.To successful status ===")
@@ -46,7 +48,10 @@ func doMainAll() {
4648
logger.Info("=== 3. NilThen and try.Out successful status ===")
4749
doMain3()
4850
}
51+
4952
func doMain3() {
53+
Init()
54+
5055
defer err2.Catch("CATCH")
5156
logger.Debug("3: ADD node")
5257
defer NilThen(func() {
@@ -56,6 +61,8 @@ func doMain3() {
5661
}
5762

5863
func doMain2() {
64+
Init()
65+
5966
defer err2.Catch("CATCH")
6067
logger.Debug("2: ADD node")
6168
defer NilThen(func() {
@@ -66,6 +73,8 @@ func doMain2() {
6673
}
6774

6875
func doMain1() {
76+
Init()
77+
6978
defer err2.Catch("CATCH")
7079
logger.Debug("1: ADD node")
7180

samples/main-play.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func OrgCopyFile(src, dst string) (err error) {
5656
return fmt.Errorf("mixing traditional error checking: %w", err)
5757
}
5858
defer err2.Handle(&err, func() {
59-
os.Remove(dst)
59+
try.Out(os.Remove(dst)).Logf("cleaning error")
6060
})
6161
defer w.Close()
6262
try.To1(io.Copy(w, r))

samples/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ func main() {
1717
log.SetFlags(log.Lshortfile | log.LstdFlags)
1818

1919
flag.Parse()
20-
Init()
2120

2221
switch *mode {
2322
case "db":

0 commit comments

Comments
 (0)