Skip to content

Conversation

@geyslan
Copy link
Member

@geyslan geyslan commented Jul 24, 2024

1. Explain what the PR does

ae857da chore(parsers): optimize ParseMmapProt

Refactor ParseMmapProt to use mmapProtArgs slice.

- Introduced mmapProtArgs slice for cleaner and more maintainable code.
- Replaced multiple if statements with a loop and string builder.
- Improved performance: reduced allocs/op from 17 to 15, and B/op from
  392 to 352.
- Execution time slightly improved from 1603 ns/op to 1536 ns/op
  (benchmark file used included).
- Reduced function size from 1534 to 677 bytes (55.8% less), what
  should improve locality and reduce cache misses.

2. Explain how to test it

3. Other comments

Refactor ParseMmapProt to use mmapProtArgs slice.

- Introduced mmapProtArgs slice for cleaner and more maintainable code.
- Replaced multiple if statements with a loop and string builder.
- Improved performance: reduced allocs/op from 17 to 15, and B/op from
  392 to 352.
- Execution time slightly improved from 1603 ns/op to 1536 ns/op
  (benchmark file used included).
- Reduced function size from 1534 to 677 bytes (55.8% less), what
  should improve locality and reduce cache misses.
@rscampos
Copy link
Collaborator

rscampos commented Aug 6, 2024

I successfully reproduced the benchmark:

goos: linux
goarch: arm64
pkg: github.com/aquasecurity/tracee/pkg/events/parsers
=== RUN   BenchmarkParseMmapProtOld
BenchmarkParseMmapProtOld
BenchmarkParseMmapProtOld-4             10000000               423.9 ns/op           392 B/op         17 allocs/op
=== RUN   BenchmarkParseMmapProtNew
BenchmarkParseMmapProtNew
BenchmarkParseMmapProtNew-4             10000000               395.1 ns/op           352 B/op         15 allocs/op
PASS
ok      github.com/aquasecurity/tracee/pkg/events/parsers       12.142s

Copy link
Collaborator

@rscampos rscampos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@geyslan geyslan merged commit 62c76c9 into aquasecurity:main Aug 6, 2024
@geyslan geyslan deleted the optimize-parsemmapprot branch February 19, 2025 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants