Skip to content

Enhance git credential helper performances #6372

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

Merged
merged 1 commit into from
Apr 29, 2025

Conversation

LucasG0
Copy link
Contributor

@LucasG0 LucasG0 commented Apr 29, 2025

From
time python helper.py: elapsed 1.31s
to
time python helper.py: elapsed 0.26s

The main improvement comes from the fact git_credential.helper imports infrahub.config, itself importing infrahub.database.constants which imports a lot of code as infrahub.database.__init__ contains a lot of logic. This PR moves these database constants in a separated infrahub.constants package that is fast to import. Note the long term fix would be to clean infrahub.database.__init__ in order to finally restore these constants within infrahub.database.

@LucasG0 LucasG0 changed the title Move database constants to constants folder Enhance git credential helper performances Apr 29, 2025
@github-actions github-actions bot added the group/backend Issue related to the backend (API Server, Git Agent) label Apr 29, 2025
Copy link

codspeed-hq bot commented Apr 29, 2025

CodSpeed Performance Report

Merging #6372 will not alter performance

Comparing lgu-boost-git-credential-helper (ee4bd26) with stable (4853eb8)

Summary

✅ 10 untouched benchmarks

@@ -51,7 +51,7 @@ def get(
raise typer.Exit(1) from exc

client = InfrahubClientSync(config=Config(address=config.SETTINGS.main.internal_address, insert_tracker=True))
repo = client.get(kind=InfrahubKind.GENERICREPOSITORY, location__value=location)
repo = client.get(kind=CoreGenericRepository.__name__, location__value=location)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This avoids importing above infrahub.core.constants, even if performance improvement is negligible. One comment on this is that all client sync methods expect dedicated sync protocols as input, but they are actually buggy as we deduce the kind from their class name (eg: CoreGenericRepositorySync in an invalid kind). That is what I used __name__ above to avoid breaking typing while using the non-sync protocol CoreGenericRepository.

Copy link
Contributor

Choose a reason for hiding this comment

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

I opened a bug in the SDK for this: opsmill/infrahub-sdk-python#380

Not convinced if we should go with the above or just use the hardcoded string "CoreGenericRepository", for now, as we're sending in a string in the above example it doesn't actually provide any extra value. Aside from having some loose reference to a "constant".

Copy link
Contributor Author

@LucasG0 LucasG0 Apr 29, 2025

Choose a reason for hiding this comment

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

Aside from having some loose reference to a "constant"

Yes that is the idea, I feel it's still better than a hardcoded string even though it is not ideal..

@LucasG0 LucasG0 marked this pull request as ready for review April 29, 2025 11:23
@LucasG0 LucasG0 requested a review from a team as a code owner April 29, 2025 11:23
@LucasG0 LucasG0 force-pushed the lgu-boost-git-credential-helper branch 2 times, most recently from dccd832 to ee4bd26 Compare April 29, 2025 12:26
Copy link
Contributor

@ogenstad ogenstad left a comment

Choose a reason for hiding this comment

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

LGTM, perhaps we should spend a minute or two on this during the daily just to explain why we have this change.

@LucasG0 LucasG0 merged commit 048608f into stable Apr 29, 2025
64 checks passed
@LucasG0 LucasG0 deleted the lgu-boost-git-credential-helper branch April 29, 2025 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
group/backend Issue related to the backend (API Server, Git Agent)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants