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

fix : SharedResourceManagedEnvContainer struct size reduction #789

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ZuhairORZaki
Copy link

@ZuhairORZaki ZuhairORZaki commented Apr 26, 2024

Description:

This PR fixes a performance issue in your codebase.

While triaging your project, our bug fixing tool found that -
In file sharedresourceloop.go theres is a struct SharedResourceManagedEnvContainer whose size can be reduced to improve memory efficiency.
sharedresourceloop.go

type SharedResourceManagedEnvContainer struct {
	ClusterUser          *db.ClusterUser
	IsNewUser            bool
	ManagedEnv           *db.ManagedEnvironment
	IsNewManagedEnv      bool
	GitopsEngineInstance *db.GitopsEngineInstance
	IsNewInstance        bool
	ClusterAccess        *db.ClusterAccess
	IsNewClusterAccess   bool
	GitopsEngineCluster  *db.GitopsEngineCluster
}

The way the struct above is defined, memory allocation for it would look something like this -
StructReduction drawio(2)
Which results in a total of 72 bytes. The extra padding bytes comes from the fact that in case of structs memory is allocated in contiguous, byte-aligned blocks to fields in the order that they are defined.

Solution

The fix is to define the struct in such a way that least number of padding bytes are introduced. The following definition results in allocation of only 48 bytes of memory as opposed to previous 72 bytes.

type SharedResourceManagedEnvContainer struct {
	ClusterUser          *db.ClusterUser
        ManagedEnv           *db.ManagedEnvironment
        GitopsEngineInstance *db.GitopsEngineInstance
        ClusterAccess        *db.ClusterAccess
	IsNewUser            bool
	IsNewManagedEnv      bool
	IsNewInstance        bool
	IsNewClusterAccess   bool
	GitopsEngineCluster  *db.GitopsEngineCluster
}

References

CLA Requirements:

This section is only relevant if your project requires contributors to sign a Contributor License Agreement (CLA) for external contributions.

All contributed commits are already automatically signed off.

The meaning of a signoff depends on the project, but it typically certifies that committer has the rights to submit this work under the same license and agrees to a Developer Certificate of Origin (see https://developercertificate.org/ for more information).

Sponsorship and Support:

This work is done by the security researchers from OpenRefactory and is supported by the Open Source Security Foundation (OpenSSF): Project Alpha-Omega. Alpha-Omega is a project partnering with open source software project maintainers to systematically find new, as-yet-undiscovered vulnerabilities in open source code - and get them fixed - to improve global software supply chain security.

The bug is found by running the iCR tool by OpenRefactory, Inc. and then manually triaging the results.

@openshift-ci openshift-ci bot requested review from chetan-rns and jopit April 26, 2024 16:45
Copy link
Contributor

openshift-ci bot commented Apr 26, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ZuhairORZaki
Once this PR has been reviewed and has the lgtm label, please assign wtam2018 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

openshift-ci bot commented Apr 26, 2024

Hi @ZuhairORZaki. Thanks for your PR.

I'm waiting for a redhat-appstudio member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

sonarcloud bot commented Apr 26, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@ZuhairORZaki ZuhairORZaki changed the title SharedResourceManagedEnvContainer struct size reduction fix : SharedResourceManagedEnvContainer struct size reduction Apr 26, 2024
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.

1 participant