-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize parser options check #4199
Conversation
633a3d4
to
45cd736
Compare
1dfbe87
to
6b9fbf6
Compare
@@ -1466,7 +1474,7 @@ func ParseMmapProt(rawValue uint64) MmapProtArgument { | |||
|
|||
var sb strings.Builder | |||
for _, a := range mmapProtArgs { | |||
if OptionAreContainedInArgument(rawValue, a) { | |||
if optionIsContainedInArgument(rawValue, a.Value()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParseMmapProt
already iterates its arguments. In the future, the loop approach can be applied to the other parser functions. Despite the improvement in CPU time the only criticism is that we need a global variable containing all arguments. But I believe this can be improved further by using pointers to existing declarations.
6b9fbf6
to
8b98236
Compare
Optimize OptionsAreContainedInArgument function to return as soon as it detects a non-contained option. Running tool: /home/gg/.goenv/versions/1.22.4/bin/go test -benchmem -run=^$ -tags ebpf -bench ^(BenchmarkOptionsAreContainedInArgumentOld|BenchmarkOptionsAreContainedInArgument)$ github.com/aquasecurity/tracee/pkg/events/parsers -benchtime=1000000x -race goos: linux goarch: amd64 pkg: github.com/aquasecurity/tracee/pkg/events/parsers cpu: AMD Ryzen 9 7950X 16-Core Processor === RUN BenchmarkOptionsAreContainedInArgumentOld BenchmarkOptionsAreContainedInArgumentOld BenchmarkOptionsAreContainedInArgumentOld-32 1000000 500.4 ns/op 0 B/op 0 allocs/op === RUN BenchmarkOptionsAreContainedInArgument BenchmarkOptionsAreContainedInArgument BenchmarkOptionsAreContainedInArgument-32 1000000 351.3 ns/op 0 B/op 0 allocs/op PASS ok github.com/aquasecurity/tracee/pkg/events/parsers 1.861s
optionsAreContainedInArgument now receives a variadic argument of type uint64 instead of SystemFunctionArgument. === RUN BenchmarkOptionsAreContainedInArgumentPrev BenchmarkOptionsAreContainedInArgumentPrev BenchmarkOptionsAreContainedInArgumentPrev-32 5000000 387.7 ns/op 0 B/op 0 allocs/op === RUN BenchmarkOptionsAreContainedInArgument BenchmarkOptionsAreContainedInArgument BenchmarkOptionsAreContainedInArgument-32 5000000 152.3 ns/op 0 B/op
Currently all usages of the `optionsAreContainedInArgument` function are using only one option. Then, `optionIsContainedInArgument` comes as a simplification of the previous function. Even though `optionsAreContainedInArgument` is not used anymore, it is still being kept for now, since some parser might need to check for multiple options in the future. === RUN Benchmark_optionsAreContainedInArgumentWithOnlyOne Benchmark_optionsAreContainedInArgumentWithOnlyOne Benchmark_optionsAreContainedInArgumentWithOnlyOne-32 5000000 174.8 ns/op 0 B/op 0 allocs/op === RUN Benchmark_optionIsContainedInArgument Benchmark_optionIsContainedInArgument Benchmark_optionIsContainedInArgument-32 5000000 140.4 ns/op 0 B/op 0 allocs/op PASS
8b98236
to
d7fa48d
Compare
double check the benchmarks and its aligned with yours: impr OptionsAreContainedInArgument:
opti optionsAreContainedInArgument:
add optionIsContainedInArgument:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
1. Explain what the PR does
d7fa48d chore(parsers): add optionIsContainedInArgument
c830bf9 chore(parsers): opti optionsAreContainedInArgument
b15d559 chore(parsers): impr OptionsAreContainedInArgument
d7fa48d chore(parsers): add optionIsContainedInArgument
c830bf9 chore(parsers): opti optionsAreContainedInArgument
b15d559 chore(parsers): impr OptionsAreContainedInArgument
2. Explain how to test it
3. Other comments