Skip to content
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

Refactor: Optimize GetCgroupPath() memory utilization #4084

Merged

Conversation

yanivagman
Copy link
Collaborator

1. Explain what the PR does

The GetCgroupPath function previously used recursion for directory traversal, which could consume excessive memory for deep directory structures. This commit refactors the function to use an iterative approach, reducing memory usage and improving performance. Additionally, the comments and error handling in the function have been updated for clarity and consistency.

2. Explain how to test it

3. Other comments

The GetCgroupPath function previously used recursion for directory traversal,
which could consume excessive memory for deep directory structures. This commit
refactors the function to use an iterative approach, reducing memory usage and
improving performance. Additionally, the comments and error handling in the
function have been updated for clarity and consistency.
@yanivagman yanivagman force-pushed the improve_get_cgroup_path_mem branch from 15d3624 to 0bc948f Compare May 29, 2024 08:25
Copy link
Collaborator

@NDStrahilevitz NDStrahilevitz left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Member

@geyslan geyslan left a comment

Choose a reason for hiding this comment

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

Great! ❤️

entryPath := filepath.Join(currentDir, entry.Name())

// Check if the entry matches the subPath (if provided)
if strings.HasSuffix(entryPath, subPath) {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps a single subPath check short circuit avoiding the next inner HasSuffix check against the two lenghts len(s) >= len(suffix). Probably negligible, anyway.

Suggested change
if strings.HasSuffix(entryPath, subPath) {
if subPath != "" && strings.HasSuffix(entryPath, subPath) {

@yanivagman yanivagman merged commit c0f0270 into aquasecurity:main May 29, 2024
32 checks passed
@yanivagman yanivagman deleted the improve_get_cgroup_path_mem branch May 29, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants