Skip to content

Commit 10fd9ee

Browse files
committed
removing logs improved performance a bit
1 parent 9e206d1 commit 10fd9ee

File tree

5 files changed

+23
-78
lines changed

5 files changed

+23
-78
lines changed

BENCHMARKS.txt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ goos: linux
22
goarch: amd64
33
pkg: github.com/miniscruff/scopie-go
44
cpu: AMD Ryzen 7 2700 Eight-Core Processor
5-
Benchmark_Validations/allow,1actor,1rule,1block1length-16 21123 48637 ns/op 16384 B/op 99 allocs/op
6-
Benchmark_Validations/deny,1actor,1rule,1block1length-16 31305 38232 ns/op 13244 B/op 86 allocs/op
7-
Benchmark_Validations/allow,5actor,3rules,3blocks10length,best-16 6146 203497 ns/op 68025 B/op 373 allocs/op
8-
Benchmark_Validations/allow,5actor,3rules,3blocks10length,worst-16 5760 190787 ns/op 81399 B/op 373 allocs/op
9-
Benchmark_Validations/deny,5actor,3rules,3blocks10length,best-16 25946 47097 ns/op 24028 B/op 90 allocs/op
10-
Benchmark_Validations/deny,5actor,3rules,3blocks10length,worst-16 5319 222343 ns/op 101802 B/op 360 allocs/op
11-
Benchmark_Validations/allow,2actor,1rule,3block5length,3array,best-16 10000 112887 ns/op 28321 B/op 222 allocs/op
12-
Benchmark_Validations/allow,2actor,1rule,3block5length,3array,worst-16 10000 129128 ns/op 65921 B/op 222 allocs/op
13-
Benchmark_Validations/deny,2actor,1rule,3block5length,3array,best-16 14275 82866 ns/op 21706 B/op 173 allocs/op
14-
Benchmark_Validations/deny,2actor,1rule,3block5length,3array,worst-16 10702 123701 ns/op 69983 B/op 209 allocs/op
15-
Benchmark_Validations/allow,3actor,1rule,3block5length,3variables,best-16 19395 64689 ns/op 18179 B/op 150 allocs/op
16-
Benchmark_Validations/allow,3actor,1rule,3block5length,3variables,worst-16 17006 64310 ns/op 18178 B/op 150 allocs/op
17-
Benchmark_Validations/deny,2actor,1rule,3block5length,3variables,best-16 28758 40788 ns/op 11600 B/op 97 allocs/op
18-
Benchmark_Validations/deny,2actor,1rule,3block5length,3variables,best#01-16 21576 57511 ns/op 15894 B/op 137 allocs/op
19-
Benchmark_Validations/allow,3actor,1rule,3block5length,wildcard,best-16 18878 61840 ns/op 16341 B/op 139 allocs/op
20-
Benchmark_Validations/allow,3actor,1rule,3block5length,wildcard,worst-16 18868 84502 ns/op 64994 B/op 139 allocs/op
21-
Benchmark_Validations/deny,2actor,1rule,3block5length,wildcard,best-16 30555 37661 ns/op 10055 B/op 86 allocs/op
22-
Benchmark_Validations/deny,2actor,1rule,3block5length,wildcard,best#01-16 19939 55444 ns/op 14311 B/op 126 allocs/op
23-
Benchmark_Validations/allow,3actor,1rule,3block5length,superwildcard,best-16 19837 63290 ns/op 16096 B/op 139 allocs/op
24-
Benchmark_Validations/allow,3actor,1rule,3block5length,superwildcard,worst-16 18422 96716 ns/op 78385 B/op 139 allocs/op
25-
Benchmark_Validations/deny,2actor,1rule,3block5length,superwildcard,best-16 33345 36821 ns/op 9827 B/op 86 allocs/op
26-
Benchmark_Validations/deny,2actor,1rule,3block5length,superwildcard,best#01-16 22474 56418 ns/op 14082 B/op 126 allocs/op
5+
Benchmark_Validations/allow,1actor,1rule,1block1length-16 788312 1293 ns/op 104 B/op 5 allocs/op
6+
Benchmark_Validations/deny,1actor,1rule,1block1length-16 742784 1547 ns/op 104 B/op 5 allocs/op
7+
Benchmark_Validations/allow,5actor,3rules,3blocks10length,best-16 238418 4333 ns/op 672 B/op 11 allocs/op
8+
Benchmark_Validations/allow,5actor,3rules,3blocks10length,worst-16 268552 4013 ns/op 672 B/op 11 allocs/op
9+
Benchmark_Validations/deny,5actor,3rules,3blocks10length,best-16 383038 2723 ns/op 416 B/op 7 allocs/op
10+
Benchmark_Validations/deny,5actor,3rules,3blocks10length,worst-16 260937 4275 ns/op 672 B/op 11 allocs/op
11+
Benchmark_Validations/allow,2actor,1rule,3block5length,3array,best-16 325629 3173 ns/op 440 B/op 10 allocs/op
12+
Benchmark_Validations/allow,2actor,1rule,3block5length,3array,worst-16 352708 3355 ns/op 440 B/op 10 allocs/op
13+
Benchmark_Validations/deny,2actor,1rule,3block5length,3array,best-16 395434 2603 ns/op 328 B/op 8 allocs/op
14+
Benchmark_Validations/deny,2actor,1rule,3block5length,3array,worst-16 332961 3143 ns/op 440 B/op 10 allocs/op
15+
Benchmark_Validations/allow,3actor,1rule,3block5length,3variables,best-16 440852 2636 ns/op 328 B/op 7 allocs/op
16+
Benchmark_Validations/allow,3actor,1rule,3block5length,3variables,worst-16 690230 2818 ns/op 328 B/op 7 allocs/op
17+
Benchmark_Validations/deny,2actor,1rule,3block5length,3variables,best-16 578025 2051 ns/op 200 B/op 5 allocs/op
18+
Benchmark_Validations/deny,2actor,1rule,3block5length,3variables,best#01-16 535602 2757 ns/op 328 B/op 7 allocs/op
19+
Benchmark_Validations/allow,3actor,1rule,3block5length,wildcard,best-16 514962 2732 ns/op 328 B/op 7 allocs/op
20+
Benchmark_Validations/allow,3actor,1rule,3block5length,wildcard,worst-16 498338 2641 ns/op 328 B/op 7 allocs/op
21+
Benchmark_Validations/deny,2actor,1rule,3block5length,wildcard,best-16 729854 1655 ns/op 200 B/op 5 allocs/op
22+
Benchmark_Validations/deny,2actor,1rule,3block5length,wildcard,best#01-16 461670 2648 ns/op 328 B/op 7 allocs/op
23+
Benchmark_Validations/allow,3actor,1rule,3block5length,superwildcard,best-16 373004 2765 ns/op 312 B/op 7 allocs/op
24+
Benchmark_Validations/allow,3actor,1rule,3block5length,superwildcard,worst-16 576085 2656 ns/op 312 B/op 7 allocs/op
25+
Benchmark_Validations/deny,2actor,1rule,3block5length,superwildcard,best-16 657088 1999 ns/op 184 B/op 5 allocs/op
26+
Benchmark_Validations/deny,2actor,1rule,3block5length,superwildcard,best#01-16 483547 2468 ns/op 312 B/op 7 allocs/op
2727
PASS
28-
ok github.com/miniscruff/scopie-go 42.260s
28+
ok github.com/miniscruff/scopie-go 33.716s

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module github.com/miniscruff/scopie-go
22

33
go 1.21
4-
5-
require github.com/neilotoole/slogt v1.1.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
github.com/neilotoole/slogt v1.1.0 h1:c7qE92sq+V0yvCuaxph+RQ2jOKL61c4hqS1Bv9W7FZE=
2-
github.com/neilotoole/slogt v1.1.0/go.mod h1:RCrGXkPc/hYybNulqQrMHRtvlQ7F6NktNVLuLwk6V+w=

scopie.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package scopie
22

33
import (
4-
"log/slog"
54
"strings"
65
)
76

@@ -22,27 +21,10 @@ const (
2221
ResultDeny Result = "deny"
2322
)
2423

25-
// Logger can be used to override the default logger,
26-
// otherwise it will use slog.Default().
27-
// Scopie only ever logs to debug level.
28-
var Logger *slog.Logger
29-
3024
// Process ...
3125
func Process(vars map[string]string, actorScopes, requiredRules string) (Result, error) {
32-
logger := Logger
33-
if logger == nil {
34-
logger = slog.Default()
35-
}
36-
37-
logger = logger.With(
38-
"actorScopes", actorScopes,
39-
"requiredRules", requiredRules,
40-
"variables", vars,
41-
)
42-
4326
// do this the simplest way for now, efficiency can come later...
4427
hasBeenAllowed := false
45-
logger.Debug("processing scopes")
4628

4729
actorScopesSplit := strings.Split(actorScopes, ScopeSeperator)
4830
ruleScopesSplit := strings.Split(requiredRules, ScopeSeperator)
@@ -63,35 +45,16 @@ func Process(vars map[string]string, actorScopes, requiredRules string) (Result,
6345

6446
for _, ruleScope := range ruleScopes {
6547
if isMatch(vars, actorScopes, ruleScope) {
66-
logger.Debug(
67-
"matched actor and rule",
68-
"actorScope", actorScope,
69-
"rule", ruleScope,
70-
)
71-
7248
if rule == string(ResultDeny) {
73-
logger.Debug(
74-
"matched deny rule",
75-
"actorScope", actorScope,
76-
"rule", ruleScope,
77-
)
78-
7949
return ResultDeny, nil
8050
} else {
81-
logger.Debug(
82-
"matched allow rule",
83-
"actorScope", actorScope,
84-
"rule", ruleScope,
85-
)
86-
8751
hasBeenAllowed = true
8852
}
8953
}
9054
}
9155
}
9256

9357
if hasBeenAllowed {
94-
logger.Debug("has been allowed")
9558
return ResultAllow, nil
9659
}
9760

@@ -101,7 +64,6 @@ func Process(vars map[string]string, actorScopes, requiredRules string) (Result,
10164
}
10265

10366
func isMatch(vars map[string]string, actorScope, ruleScope []string) bool {
104-
slog.Info("checking a match", "actor", actorScope, "rule", ruleScope)
10567
NextRule:
10668
for i, ruleBlock := range ruleScope {
10769
if len(actorScope) <= i {
@@ -117,10 +79,8 @@ NextRule:
11779
}
11880

11981
if strings.Contains(actorBlock, ArraySeperator) {
120-
slog.Info("comparing rule array to scope", "rule array", ruleBlock)
12182
for _, actorArrayValue := range strings.Split(actorBlock, ArraySeperator) {
12283
if actorArrayValue == ruleBlock {
123-
slog.Info("found matching array value", "value", actorArrayValue)
12484
continue NextRule
12585
}
12686
}

scopie_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ package scopie
22

33
import (
44
"encoding/json"
5-
"log/slog"
65
"os"
76
"testing"
87

9-
"github.com/neilotoole/slogt"
10-
118
"github.com/miniscruff/scopie-go/then"
129
)
1310

@@ -25,14 +22,6 @@ type validationTestCase struct {
2522
}
2623

2724
func LoadScenarios(t testing.TB) validationTestCase {
28-
slogDef := slog.Default()
29-
t.Cleanup(func() {
30-
slog.SetDefault(slogDef)
31-
})
32-
33-
testLog := slogt.New(t, slogt.JSON())
34-
slog.SetDefault(testLog)
35-
3625
testFile, err := os.Open("testdata/scopie_scenarios.json")
3726
then.Nil(t, err)
3827

0 commit comments

Comments
 (0)