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: removing duplicated nuget packages folder #746

Merged
merged 4 commits into from
Jan 28, 2025

Conversation

pranav-firake
Copy link
Contributor

@pranav-firake pranav-firake commented Jan 24, 2025

Problem

V1642391964
Currently when we are packaging artifacts.zip on the IDE, the nuget packages are part of

  1. default "packages" folder in the root solution/ source Code
  2. newly created the references folder in artifactsWorkspace.

This is causing increased artifacts size.

Solution

we are not using packages folder from sourceCode for transformations in Qnet CLI, we are only using nuget packages from references folder.
So we can safely delete packages folder before zipping to save on space.

Simple example on saving space is
Sample applications - Bobs Bookstore
Size of packages folder - 241MB

size of Artifacts zip BEFORE below changes of deduping - 179 MB

image

size of Artifacts zip AFTER below changes of deduping - 89 MB
image

we are saving almost 45% space in artifacts zipping and thereby for uploads. This will also benefit for customer issues with large codebase

UPDATE :

Also found that copyFile is async and we are zipping / deleting package folder even before all copying is complete. so changed copyFile to Sync operation

Testing

Case : Updated a BobsBookstore application to bloat to 2.3 GB of artifacts.zip.
with deduping, for same project artifacts size is - 1.2 GB

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@pranav-firake pranav-firake requested a review from a team as a code owner January 24, 2025 08:13
@pranav-firake pranav-firake changed the title fix: removing duplicated nuget packages folder [internal review] fix: removing duplicated nuget packages folder Jan 24, 2025
@marknfawaz
Copy link

Please add how this was tested.

packagesFolderName
)
if (!fs.existsSync(packagesFolder)) {
this.logging.log('Cannot find nuget packages folder in source code')

Choose a reason for hiding this comment

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

Why do we need to log this?

Copy link

@jonlouie jonlouie Jan 24, 2025

Choose a reason for hiding this comment

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

+1. If we invert the if logic, we can simplify this method. Then reducing the logging becomes natural.

Copy link
Contributor Author

@pranav-firake pranav-firake Jan 24, 2025

Choose a reason for hiding this comment

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

agreed, it is causing unnecessary logs, will remove this.
will add just return here instead of logging

)
if (fs.existsSync(packagesFolder)) {
fs.rmSync(packagesFolder, { recursive: true, force: true })
this.logging.log(`Removed nuget packages folder: ${packagesFolder}`)
Copy link

@jonlouie jonlouie Jan 27, 2025

Choose a reason for hiding this comment

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

One more thing: In the log message, we should say why it is removed (e.g. "Removed packages folder {packagesFolder} from directory containing artifacts to be uploaded because it is a duplicate of {nugetFolder}").

Going forward, we should be mindful of the messages we log. They should provide enough context so the reader understands the intended behavior without having any knowledge of the code itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for suggestion, updated logging message accordingly

@@ -41,6 +43,21 @@ export class ArtifactManager {
}
}

async removeDuplicateNugetPackagesFolder(request: StartTransformRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

as a potential optimization, is it possible to skip adding these files to the zip in the first place. If I understand correctly right now we spend extra time copying these files in the step before only to end up going through the folder again and deleting them. If we could create the artifacts in a single go that would also make the process more efficient. Is this possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes Ege, thanks for suggestion.
After this hotfix, we will take a stab in detail on optimizing entire zipping with ticket P194692593.

@ege0zcan
Copy link
Contributor

Small reminder to remove the [internal-review] prefix before merging, otherwise the commit linter rules will prevent the merge

@pranav-firake pranav-firake changed the title [internal review] fix: removing duplicated nuget packages folder fix: removing duplicated nuget packages folder Jan 28, 2025
@pranav-firake pranav-firake merged commit 24b44d0 into main Jan 28, 2025
6 checks passed
@pranav-firake pranav-firake deleted the pranavfi-fix-for-deduping-nuget-packages-folder branch January 28, 2025 17:47
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.

4 participants