Skip to content

Commit 51a951f

Browse files
🐛 address performance issue with perl (#751)
Signed-off-by: Pranav Gaikwad <[email protected]>
1 parent 6e059e8 commit 51a951f

File tree

4 files changed

+191
-2
lines changed

4 files changed

+191
-2
lines changed

.github/workflows/benchmark.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Run benchmark tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
benchmark:
13+
runs-on: ${{ matrix.os.id }}
14+
15+
strategy:
16+
matrix:
17+
os:
18+
- id: macos-latest
19+
name: mac
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v3
24+
25+
- name: Set up Go
26+
uses: actions/setup-go@v4
27+
with:
28+
go-version: '1.21'
29+
30+
- name: Run benchmark tests
31+
run: |
32+
go install golang.org/x/perf/cmd/benchstat@latest
33+
go mod tidy
34+
go test -run=^$ -bench=. -benchmem -count=6 ./... > benchmark_results
35+
36+
- name: Display Benchstat results
37+
run: benchstat benchmark.${{ matrix.os.name }} benchmark_results

benchmark.mac

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
? github.com/konveyor/analyzer-lsp/cmd/analyzer [no test files]
2+
? github.com/konveyor/analyzer-lsp/cmd/dep [no test files]
3+
PASS
4+
ok github.com/konveyor/analyzer-lsp/engine 0.401s
5+
PASS
6+
ok github.com/konveyor/analyzer-lsp/engine/internal 0.343s
7+
PASS
8+
ok github.com/konveyor/analyzer-lsp/engine/labels 0.303s
9+
goos: darwin
10+
goarch: arm64
11+
pkg: github.com/konveyor/analyzer-lsp/event
12+
cpu: Apple M2 Pro
13+
Benchmark/Baseline-12 24095722 50.54 ns/op 0 B/op 0 allocs/op
14+
Benchmark/Baseline-12 23726140 49.87 ns/op 0 B/op 0 allocs/op
15+
Benchmark/Baseline-12 23899740 49.84 ns/op 0 B/op 0 allocs/op
16+
Benchmark/Baseline-12 24208536 49.64 ns/op 0 B/op 0 allocs/op
17+
Benchmark/Baseline-12 24224194 49.56 ns/op 0 B/op 0 allocs/op
18+
Benchmark/Baseline-12 24192754 49.65 ns/op 0 B/op 0 allocs/op
19+
Benchmark/StdLog-12 4844557 247.6 ns/op 152 B/op 12 allocs/op
20+
Benchmark/StdLog-12 4867081 246.8 ns/op 152 B/op 12 allocs/op
21+
Benchmark/StdLog-12 4861424 247.7 ns/op 152 B/op 12 allocs/op
22+
Benchmark/StdLog-12 4803439 247.4 ns/op 152 B/op 12 allocs/op
23+
Benchmark/StdLog-12 4855087 247.6 ns/op 152 B/op 12 allocs/op
24+
Benchmark/StdLog-12 4815972 247.2 ns/op 152 B/op 12 allocs/op
25+
Benchmark/LogNoExporter-12 3493294 344.3 ns/op 0 B/op 0 allocs/op
26+
Benchmark/LogNoExporter-12 3489210 344.1 ns/op 0 B/op 0 allocs/op
27+
Benchmark/LogNoExporter-12 3488331 343.6 ns/op 0 B/op 0 allocs/op
28+
Benchmark/LogNoExporter-12 3485558 344.0 ns/op 0 B/op 0 allocs/op
29+
Benchmark/LogNoExporter-12 3491460 343.8 ns/op 0 B/op 0 allocs/op
30+
Benchmark/LogNoExporter-12 3493819 343.6 ns/op 0 B/op 0 allocs/op
31+
Benchmark/TraceNoExporter-12 1000000 1060 ns/op 2816 B/op 16 allocs/op
32+
Benchmark/TraceNoExporter-12 1000000 1057 ns/op 2816 B/op 16 allocs/op
33+
Benchmark/TraceNoExporter-12 1000000 1063 ns/op 2816 B/op 16 allocs/op
34+
Benchmark/TraceNoExporter-12 1000000 1059 ns/op 2816 B/op 16 allocs/op
35+
Benchmark/TraceNoExporter-12 1000000 1056 ns/op 2816 B/op 16 allocs/op
36+
Benchmark/TraceNoExporter-12 1000000 1058 ns/op 2816 B/op 16 allocs/op
37+
Benchmark/StatsNoExporter-12 2286189 524.4 ns/op 0 B/op 0 allocs/op
38+
Benchmark/StatsNoExporter-12 2283171 524.1 ns/op 0 B/op 0 allocs/op
39+
Benchmark/StatsNoExporter-12 2288745 529.0 ns/op 0 B/op 0 allocs/op
40+
Benchmark/StatsNoExporter-12 2288671 524.7 ns/op 0 B/op 0 allocs/op
41+
Benchmark/StatsNoExporter-12 2289902 524.8 ns/op 0 B/op 0 allocs/op
42+
Benchmark/StatsNoExporter-12 2287399 524.3 ns/op 0 B/op 0 allocs/op
43+
Benchmark/LogNoop-12 800296 1476 ns/op 2816 B/op 16 allocs/op
44+
Benchmark/LogNoop-12 809149 1474 ns/op 2816 B/op 16 allocs/op
45+
Benchmark/LogNoop-12 814642 1473 ns/op 2816 B/op 16 allocs/op
46+
Benchmark/LogNoop-12 804619 1476 ns/op 2816 B/op 16 allocs/op
47+
Benchmark/LogNoop-12 813055 1475 ns/op 2816 B/op 16 allocs/op
48+
Benchmark/LogNoop-12 801357 1476 ns/op 2816 B/op 16 allocs/op
49+
Benchmark/TraceNoop-12 320142 3751 ns/op 9216 B/op 64 allocs/op
50+
Benchmark/TraceNoop-12 318978 3765 ns/op 9216 B/op 64 allocs/op
51+
Benchmark/TraceNoop-12 317174 3762 ns/op 9216 B/op 64 allocs/op
52+
Benchmark/TraceNoop-12 321618 3751 ns/op 9216 B/op 64 allocs/op
53+
Benchmark/TraceNoop-12 318663 3752 ns/op 9216 B/op 64 allocs/op
54+
Benchmark/TraceNoop-12 316610 3737 ns/op 9216 B/op 64 allocs/op
55+
Benchmark/StatsNoop-12 432556 2757 ns/op 5632 B/op 32 allocs/op
56+
Benchmark/StatsNoop-12 431367 2755 ns/op 5632 B/op 32 allocs/op
57+
Benchmark/StatsNoop-12 439297 2759 ns/op 5632 B/op 32 allocs/op
58+
Benchmark/StatsNoop-12 438567 2756 ns/op 5632 B/op 32 allocs/op
59+
Benchmark/StatsNoop-12 435147 2753 ns/op 5632 B/op 32 allocs/op
60+
Benchmark/StatsNoop-12 434988 2815 ns/op 5632 B/op 32 allocs/op
61+
Benchmark/Log-12 217500 5545 ns/op 2816 B/op 16 allocs/op
62+
Benchmark/Log-12 213459 5557 ns/op 2816 B/op 16 allocs/op
63+
Benchmark/Log-12 217459 5535 ns/op 2816 B/op 16 allocs/op
64+
Benchmark/Log-12 215778 5536 ns/op 2816 B/op 16 allocs/op
65+
Benchmark/Log-12 213157 5542 ns/op 2816 B/op 16 allocs/op
66+
Benchmark/Log-12 215679 5541 ns/op 2816 B/op 16 allocs/op
67+
Benchmark/Trace-12 57816 20692 ns/op 22222 B/op 384 allocs/op
68+
Benchmark/Trace-12 57600 20707 ns/op 22222 B/op 384 allocs/op
69+
Benchmark/Trace-12 58332 20819 ns/op 22223 B/op 384 allocs/op
70+
Benchmark/Trace-12 57784 20719 ns/op 22223 B/op 384 allocs/op
71+
Benchmark/Trace-12 58201 20829 ns/op 22223 B/op 384 allocs/op
72+
Benchmark/Trace-12 58064 20801 ns/op 22223 B/op 384 allocs/op
73+
Benchmark/Stats-12 247478 5032 ns/op 5632 B/op 32 allocs/op
74+
Benchmark/Stats-12 240490 5104 ns/op 5632 B/op 32 allocs/op
75+
Benchmark/Stats-12 235659 4923 ns/op 5632 B/op 32 allocs/op
76+
Benchmark/Stats-12 234410 4951 ns/op 5632 B/op 32 allocs/op
77+
Benchmark/Stats-12 242782 4903 ns/op 5632 B/op 32 allocs/op
78+
Benchmark/Stats-12 234861 5083 ns/op 5632 B/op 32 allocs/op
79+
PASS
80+
ok github.com/konveyor/analyzer-lsp/event 89.042s
81+
? github.com/konveyor/analyzer-lsp/event/core [no test files]
82+
PASS
83+
ok github.com/konveyor/analyzer-lsp/event/export 0.270s
84+
? github.com/konveyor/analyzer-lsp/event/export/eventtest [no test files]
85+
? github.com/konveyor/analyzer-lsp/event/export/metric [no test files]
86+
PASS
87+
ok github.com/konveyor/analyzer-lsp/event/export/ocagent 0.364s
88+
PASS
89+
ok github.com/konveyor/analyzer-lsp/event/export/ocagent/wire 0.278s
90+
? github.com/konveyor/analyzer-lsp/event/export/prometheus [no test files]
91+
? github.com/konveyor/analyzer-lsp/event/keys [no test files]
92+
PASS
93+
ok github.com/konveyor/analyzer-lsp/event/label 0.243s
94+
? github.com/konveyor/analyzer-lsp/event/tag [no test files]
95+
? github.com/konveyor/analyzer-lsp/jsonrpc2 [no test files]
96+
PASS
97+
ok github.com/konveyor/analyzer-lsp/jsonrpc2_v2 0.245s
98+
? github.com/konveyor/analyzer-lsp/lsp/base_service_client [no test files]
99+
? github.com/konveyor/analyzer-lsp/lsp/protocol [no test files]
100+
PASS
101+
ok github.com/konveyor/analyzer-lsp/lsp/protocol/generate 0.359s
102+
? github.com/konveyor/analyzer-lsp/output/v1/konveyor [no test files]
103+
PASS
104+
ok github.com/konveyor/analyzer-lsp/parser 0.322s
105+
goos: darwin
106+
goarch: arm64
107+
pkg: github.com/konveyor/analyzer-lsp/provider
108+
cpu: Apple M2 Pro
109+
BenchmarkMultilineGrepFileSizeSmall-12 18542 66409 ns/op 56058 B/op 322 allocs/op
110+
BenchmarkMultilineGrepFileSizeSmall-12 18519 67844 ns/op 56106 B/op 322 allocs/op
111+
BenchmarkMultilineGrepFileSizeSmall-12 18536 65137 ns/op 56021 B/op 322 allocs/op
112+
BenchmarkMultilineGrepFileSizeSmall-12 18601 65112 ns/op 56100 B/op 322 allocs/op
113+
BenchmarkMultilineGrepFileSizeSmall-12 17031 67742 ns/op 56140 B/op 322 allocs/op
114+
BenchmarkMultilineGrepFileSizeSmall-12 18585 64159 ns/op 56015 B/op 322 allocs/op
115+
BenchmarkMultilineGrepFileSizeBig-12 2812 419900 ns/op 201959 B/op 2224 allocs/op
116+
BenchmarkMultilineGrepFileSizeBig-12 2863 419901 ns/op 202090 B/op 2224 allocs/op
117+
BenchmarkMultilineGrepFileSizeBig-12 2820 420061 ns/op 202098 B/op 2224 allocs/op
118+
BenchmarkMultilineGrepFileSizeBig-12 2852 419859 ns/op 201826 B/op 2224 allocs/op
119+
BenchmarkMultilineGrepFileSizeBig-12 2814 420313 ns/op 201906 B/op 2224 allocs/op
120+
BenchmarkMultilineGrepFileSizeBig-12 2844 421526 ns/op 202314 B/op 2224 allocs/op
121+
PASS
122+
ok github.com/konveyor/analyzer-lsp/provider 19.117s
123+
? github.com/konveyor/analyzer-lsp/provider/grpc [no test files]
124+
goos: darwin
125+
goarch: arm64
126+
pkg: github.com/konveyor/analyzer-lsp/provider/internal/builtin
127+
cpu: Apple M2 Pro
128+
BenchmarkRunOSSpecificGrepCommand-12 69 17053207 ns/op 43916 B/op 65 allocs/op
129+
BenchmarkRunOSSpecificGrepCommand-12 72 17169915 ns/op 43725 B/op 64 allocs/op
130+
BenchmarkRunOSSpecificGrepCommand-12 73 16839756 ns/op 43707 B/op 64 allocs/op
131+
BenchmarkRunOSSpecificGrepCommand-12 69 17492351 ns/op 43743 B/op 64 allocs/op
132+
BenchmarkRunOSSpecificGrepCommand-12 76 16651446 ns/op 43775 B/op 64 allocs/op
133+
BenchmarkRunOSSpecificGrepCommand-12 70 17191546 ns/op 43852 B/op 65 allocs/op
134+
PASS
135+
ok github.com/konveyor/analyzer-lsp/provider/internal/builtin 8.223s
136+
? github.com/konveyor/analyzer-lsp/provider/internal/grpc [no test files]
137+
? github.com/konveyor/analyzer-lsp/provider/lib [no test files]
138+
? github.com/konveyor/analyzer-lsp/tracing [no test files]

provider/internal/builtin/service_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,8 @@ func runOSSpecificGrepCommand(pattern string, location string, providerContext p
624624
escapedPattern = strings.ReplaceAll(escapedPattern, "'", "'\\''")
625625
escapedPattern = strings.ReplaceAll(escapedPattern, "$", "\\$")
626626
cmd := fmt.Sprintf(
627-
`find %v -type f | \
628-
while read file; do perl -ne '/%v/ && print "$ARGV:$.:$1\n";' "$file"; done`,
627+
`find %v -type f -print0 | \
628+
xargs -0 perl -ne '/%v/ && print "$ARGV:$.:$1\n";'`,
629629
location, escapedPattern,
630630
)
631631
findstr := exec.Command("/bin/sh", "-c", cmd)

provider/internal/builtin/service_client_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package builtin
22

33
import (
44
"context"
5+
"path/filepath"
56
"reflect"
67
"sync"
78
"testing"
89

910
"github.com/go-logr/logr/testr"
11+
"github.com/konveyor/analyzer-lsp/engine"
1012
"github.com/konveyor/analyzer-lsp/provider"
1113
)
1214

@@ -122,3 +124,15 @@ func Test_builtinServiceClient_filterByIncludedPaths(t *testing.T) {
122124
})
123125
}
124126
}
127+
128+
func BenchmarkRunOSSpecificGrepCommand(b *testing.B) {
129+
for i := 0; i < b.N; i++ {
130+
path, err := filepath.Abs("../../../external-providers/java-external-provider/examples/customers-tomcat-legacy/")
131+
if err != nil {
132+
return
133+
}
134+
runOSSpecificGrepCommand("Apache License 1.1",
135+
path,
136+
provider.ProviderContext{Template: map[string]engine.ChainTemplate{}})
137+
}
138+
}

0 commit comments

Comments
 (0)