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

Reduce install size of clients by removing unnecessary files from published tarball #2797

Closed
trivikr opened this issue Sep 20, 2021 · 2 comments · Fixed by #2873
Closed

Reduce install size of clients by removing unnecessary files from published tarball #2797

trivikr opened this issue Sep 20, 2021 · 2 comments · Fixed by #2873
Labels
feature-request New feature or enhancement. May require GitHub community feedback.

Comments

@trivikr
Copy link
Member

trivikr commented Sep 20, 2021

Is your feature request related to a problem? Please describe.

The modular packages in AWS SDK for JavaScript (v3) reduce the bundle size on tree-shaking, but the clients take too much space in node_modules. This affects runtime environments where users do not bundle the SSDK (like AWS Lambda).

Script to compute bundle sizes for clients
const { readdirSync, readFileSync, statSync } = require("fs");
const { join } = require("path");
const { spawnSync } = require("child_process");

const { packages } = JSON.parse(readFileSync(join(process.cwd(), "package.json"))).workspaces;

const getAllFiles = (dirPath, arrayOfFiles) => {
  files = readdirSync(dirPath);

  arrayOfFiles = arrayOfFiles || [];

  files.forEach((file) => {
    if (statSync(dirPath + "/" + file).isDirectory()) {
      arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles);
    } else {
      arrayOfFiles.push(join(dirPath, "/", file));
    }
  });

  return arrayOfFiles;
};

let totalSizeInMB = 0;

spawnSync("git", ["clean", "-dfx"]);
spawnSync("yarn");
spawnSync("yarn", ["build:all"]);
spawnSync("./node_modules/.bin/lerna", ["run", "downlevel-dts"]);

const packageNameColLength = 50;
const sizeColLength = 15;
const packageSizeList = [];

packages
  .map((dir) => dir.replace("/*", ""))
  .forEach((workspacesDir) => {
    // Process each workspace in workspace directory
    readdirSync(join(process.cwd(), workspacesDir), { withFileTypes: true })
      .filter((dirent) => dirent.isDirectory())
      .map((dirent) => dirent.name)
      .forEach((workspaceDir) => {
        if (!workspaceDir.startsWith("client-")) {
          return;
        }
        try {
          // npm pack posts debug messages to stderr
          // Refs: https://github.com/npm/npm/issues/118#issuecomment-325440
          const { stderr } = spawnSync("npm", ["pack", "--dry-run"], {
            cwd: join(process.cwd(), workspacesDir, workspaceDir),
          });
          const packageName = `@aws-sdk/${workspaceDir}`;
          const unpackedSize = stderr
            .toString()
            .match(/unpacked size: ([^\n]*)/)[1]
            .trim();
          packageSizeList.push({ packageName, unpackedSize });
          const [size, unit] = unpackedSize.split(" ");
          totalSizeInMB += size / (unit === "kB" ? 1024 : 1);
        } catch (error) {
          console.log(`${workspaceDir}: ${error}`);
        }
      });
  });

console.log(`Total size: ${totalSizeInMB.toFixed(2)} MB\n`);

console.log(`| ${"Package name".padEnd(packageNameColLength)} | ${"Unpacked size".padEnd(sizeColLength)} |`);
console.log(`|-${"-".padEnd(packageNameColLength, "-")}-|-${"-".padEnd(sizeColLength, "-")}-|`);
packageSizeList.forEach(({ packageName, unpackedSize }) =>
  console.log(`| ${packageName.padEnd(packageNameColLength)} | ${unpackedSize.padEnd(sizeColLength)} |`)
);
Bundle sizes of clients

Total size: 803.77 MB

Package name Unpacked size
@aws-sdk/client-accessanalyzer 2.3 MB
@aws-sdk/client-acm 1.3 MB
@aws-sdk/client-acm-pca 2.1 MB
@aws-sdk/client-alexa-for-business 5.2 MB
@aws-sdk/client-amp 630.4 kB
@aws-sdk/client-amplify 2.4 MB
@aws-sdk/client-amplifybackend 1.8 MB
@aws-sdk/client-api-gateway 7.8 MB
@aws-sdk/client-apigatewaymanagementapi 360.3 kB
@aws-sdk/client-apigatewayv2 4.8 MB
@aws-sdk/client-app-mesh 3.9 MB
@aws-sdk/client-appconfig 2.2 MB
@aws-sdk/client-appflow 2.2 MB
@aws-sdk/client-appintegrations 678.0 kB
@aws-sdk/client-application-auto-scaling 1.6 MB
@aws-sdk/client-application-discovery-service 2.0 MB
@aws-sdk/client-application-insights 1.8 MB
@aws-sdk/client-applicationcostprofiler 525.4 kB
@aws-sdk/client-apprunner 1.6 MB
@aws-sdk/client-appstream 3.2 MB
@aws-sdk/client-appsync 2.7 MB
@aws-sdk/client-athena 2.2 MB
@aws-sdk/client-auditmanager 3.4 MB
@aws-sdk/client-auto-scaling 4.7 MB
@aws-sdk/client-auto-scaling-plans 824.2 kB
@aws-sdk/client-backup 4.5 MB
@aws-sdk/client-batch 2.0 MB
@aws-sdk/client-braket 723.3 kB
@aws-sdk/client-budgets 1.8 MB
@aws-sdk/client-chime 12.5 MB
@aws-sdk/client-chime-sdk-identity 1.2 MB
@aws-sdk/client-chime-sdk-messaging 2.3 MB
@aws-sdk/client-cloud9 1.1 MB
@aws-sdk/client-clouddirectory 5.3 MB
@aws-sdk/client-cloudformation 5.7 MB
@aws-sdk/client-cloudfront 7.6 MB
@aws-sdk/client-cloudhsm 1.3 MB
@aws-sdk/client-cloudhsm-v2 1.1 MB
@aws-sdk/client-cloudsearch 2.0 MB
@aws-sdk/client-cloudsearch-domain 532.5 kB
@aws-sdk/client-cloudtrail 1.9 MB
@aws-sdk/client-cloudwatch 2.9 MB
@aws-sdk/client-cloudwatch-events 3.5 MB
@aws-sdk/client-cloudwatch-logs 2.7 MB
@aws-sdk/client-codeartifact 2.7 MB
@aws-sdk/client-codebuild 3.5 MB
@aws-sdk/client-codecommit 7.6 MB
@aws-sdk/client-codedeploy 4.4 MB
@aws-sdk/client-codeguru-reviewer 1.4 MB
@aws-sdk/client-codeguruprofiler 1.8 MB
@aws-sdk/client-codepipeline 3.2 MB
@aws-sdk/client-codestar 1.3 MB
@aws-sdk/client-codestar-connections 849.4 kB
@aws-sdk/client-codestar-notifications 1.0 MB
@aws-sdk/client-cognito-identity 1.7 MB
@aws-sdk/client-cognito-identity-provider 7.9 MB
@aws-sdk/client-cognito-sync 1.5 MB
@aws-sdk/client-comprehend 4.4 MB
@aws-sdk/client-comprehendmedical 1.5 MB
@aws-sdk/client-compute-optimizer 1.8 MB
@aws-sdk/client-config-service 6.7 MB
@aws-sdk/client-connect 7.2 MB
@aws-sdk/client-connect-contact-lens 290.5 kB
@aws-sdk/client-connectparticipant 747.0 kB
@aws-sdk/client-cost-and-usage-report-service 479.5 kB
@aws-sdk/client-cost-explorer 2.9 MB
@aws-sdk/client-customer-profiles 2.3 MB
@aws-sdk/client-data-pipeline 1.6 MB
@aws-sdk/client-database-migration-service 5.0 MB
@aws-sdk/client-databrew 2.7 MB
@aws-sdk/client-dataexchange 1.7 MB
@aws-sdk/client-datasync 2.3 MB
@aws-sdk/client-dax 1.6 MB
@aws-sdk/client-detective 1.1 MB
@aws-sdk/client-device-farm 5.0 MB
@aws-sdk/client-devops-guru 1.9 MB
@aws-sdk/client-direct-connect 3.6 MB
@aws-sdk/client-directory-service 4.2 MB
@aws-sdk/client-dlm 861.9 kB
@aws-sdk/client-docdb 4.3 MB
@aws-sdk/client-dynamodb 5.1 MB
@aws-sdk/client-dynamodb-streams 591.5 kB
@aws-sdk/client-ebs 713.0 kB
@aws-sdk/client-ec2 34.1 MB
@aws-sdk/client-ec2-instance-connect 371.2 kB
@aws-sdk/client-ecr 2.5 MB
@aws-sdk/client-ecr-public 1.7 MB
@aws-sdk/client-ecs 5.2 MB
@aws-sdk/client-efs 2.2 MB
@aws-sdk/client-eks 2.9 MB
@aws-sdk/client-elastic-beanstalk 3.5 MB
@aws-sdk/client-elastic-inference 576.5 kB
@aws-sdk/client-elastic-load-balancing 2.3 MB
@aws-sdk/client-elastic-load-balancing-v2 3.1 MB
@aws-sdk/client-elastic-transcoder 2.1 MB
@aws-sdk/client-elasticache 6.2 MB
@aws-sdk/client-elasticsearch-service 3.3 MB
@aws-sdk/client-emr 3.9 MB
@aws-sdk/client-emr-containers 1.1 MB
@aws-sdk/client-eventbridge 3.5 MB
@aws-sdk/client-finspace 601.8 kB
@aws-sdk/client-finspace-data 360.0 kB
@aws-sdk/client-firehose 1.8 MB
@aws-sdk/client-fis 1.1 MB
@aws-sdk/client-fms 2.1 MB
@aws-sdk/client-forecast 2.8 MB
@aws-sdk/client-forecastquery 305.9 kB
@aws-sdk/client-frauddetector 3.6 MB
@aws-sdk/client-fsx 2.9 MB
@aws-sdk/client-gamelift 8.1 MB
@aws-sdk/client-glacier 2.8 MB
@aws-sdk/client-global-accelerator 3.3 MB
@aws-sdk/client-glue 10.9 MB
@aws-sdk/client-greengrass 5.1 MB
@aws-sdk/client-greengrassv2 2.0 MB
@aws-sdk/client-groundstation 1.8 MB
@aws-sdk/client-guardduty 3.7 MB
@aws-sdk/client-health 1.3 MB
@aws-sdk/client-healthlake 976.0 kB
@aws-sdk/client-honeycode 1.3 MB
@aws-sdk/client-iam 10.6 MB
@aws-sdk/client-identitystore 443.0 kB
@aws-sdk/client-imagebuilder 3.8 MB
@aws-sdk/client-inspector 2.7 MB
@aws-sdk/client-iot 15.9 MB
@aws-sdk/client-iot-1click-devices-service 897.4 kB
@aws-sdk/client-iot-1click-projects 1.1 MB
@aws-sdk/client-iot-data-plane 676.9 kB
@aws-sdk/client-iot-events 2.3 MB
@aws-sdk/client-iot-events-data 1.0 MB
@aws-sdk/client-iot-jobs-data-plane 524.4 kB
@aws-sdk/client-iot-wireless 3.6 MB
@aws-sdk/client-iotanalytics 2.7 MB
@aws-sdk/client-iotdeviceadvisor 919.8 kB
@aws-sdk/client-iotfleethub 609.7 kB
@aws-sdk/client-iotsecuretunneling 584.9 kB
@aws-sdk/client-iotsitewise 4.6 MB
@aws-sdk/client-iotthingsgraph 2.3 MB
@aws-sdk/client-ivs 1.8 MB
@aws-sdk/client-kafka 2.3 MB
@aws-sdk/client-kafkaconnect 1.1 MB
@aws-sdk/client-kendra 3.9 MB
@aws-sdk/client-kinesis 2.3 MB
@aws-sdk/client-kinesis-analytics 1.9 MB
@aws-sdk/client-kinesis-analytics-v2 2.9 MB
@aws-sdk/client-kinesis-video 1.4 MB
@aws-sdk/client-kinesis-video-archived-media 974.6 kB
@aws-sdk/client-kinesis-video-media 328.1 kB
@aws-sdk/client-kinesis-video-signaling 337.2 kB
@aws-sdk/client-kms 4.7 MB
@aws-sdk/client-lakeformation 1.7 MB
@aws-sdk/client-lambda 4.7 MB
@aws-sdk/client-lex-model-building-service 3.5 MB
@aws-sdk/client-lex-models-v2 4.7 MB
@aws-sdk/client-lex-runtime-service 955.2 kB
@aws-sdk/client-lex-runtime-v2 1.1 MB
@aws-sdk/client-license-manager 3.2 MB
@aws-sdk/client-lightsail 10.6 MB
@aws-sdk/client-location 3.7 MB
@aws-sdk/client-lookoutequipment 1.6 MB
@aws-sdk/client-lookoutmetrics 1.9 MB
@aws-sdk/client-lookoutvision 1.5 MB
@aws-sdk/client-machine-learning 2.3 MB
@aws-sdk/client-macie 641.8 kB
@aws-sdk/client-macie2 4.5 MB
@aws-sdk/client-managedblockchain 1.9 MB
@aws-sdk/client-marketplace-catalog 696.3 kB
@aws-sdk/client-marketplace-commerce-analytics 366.0 kB
@aws-sdk/client-marketplace-entitlement-service 325.2 kB
@aws-sdk/client-marketplace-metering 651.3 kB
@aws-sdk/client-mediaconnect 2.4 MB
@aws-sdk/client-mediaconvert 4.9 MB
@aws-sdk/client-medialive 6.4 MB
@aws-sdk/client-mediapackage 1.6 MB
@aws-sdk/client-mediapackage-vod 1.4 MB
@aws-sdk/client-mediastore 1.3 MB
@aws-sdk/client-mediastore-data 526.6 kB
@aws-sdk/client-mediatailor 2.1 MB
@aws-sdk/client-memorydb 2.5 MB
@aws-sdk/client-mgn 1.9 MB
@aws-sdk/client-migration-hub 1.5 MB
@aws-sdk/client-migrationhub-config 444.6 kB
@aws-sdk/client-mobile 791.6 kB
@aws-sdk/client-mq 1.7 MB
@aws-sdk/client-mturk 2.6 MB
@aws-sdk/client-mwaa 903.1 kB
@aws-sdk/client-neptune 5.3 MB
@aws-sdk/client-network-firewall 2.5 MB
@aws-sdk/client-networkmanager 2.5 MB
@aws-sdk/client-nimble 3.2 MB
@aws-sdk/client-opensearch 3.1 MB
@aws-sdk/client-opsworks 4.8 MB
@aws-sdk/client-opsworkscm 1.5 MB
@aws-sdk/client-organizations 4.5 MB
@aws-sdk/client-outposts 843.1 kB
@aws-sdk/client-personalize 3.2 MB
@aws-sdk/client-personalize-events 383.3 kB
@aws-sdk/client-personalize-runtime 347.7 kB
@aws-sdk/client-pi 527.1 kB
@aws-sdk/client-pinpoint 8.8 MB
@aws-sdk/client-pinpoint-email 3.0 MB
@aws-sdk/client-pinpoint-sms-voice 729.7 kB
@aws-sdk/client-polly 909.1 kB
@aws-sdk/client-pricing 477.6 kB
@aws-sdk/client-proton 3.6 MB
@aws-sdk/client-qldb 1.5 MB
@aws-sdk/client-qldb-session 411.5 kB
@aws-sdk/client-quicksight 9.1 MB
@aws-sdk/client-ram 2.0 MB
@aws-sdk/client-rds 12.2 MB
@aws-sdk/client-rds-data 795.0 kB
@aws-sdk/client-redshift 9.0 MB
@aws-sdk/client-redshift-data 924.5 kB
@aws-sdk/client-rekognition 4.7 MB
@aws-sdk/client-resource-groups 1.4 MB
@aws-sdk/client-resource-groups-tagging-api 855.8 kB
@aws-sdk/client-robomaker 4.2 MB
@aws-sdk/client-route-53 5.3 MB
@aws-sdk/client-route-53-domains 2.1 MB
@aws-sdk/client-route53-recovery-cluster 389.0 kB
@aws-sdk/client-route53-recovery-control-config 1.5 MB
@aws-sdk/client-route53-recovery-readiness 2.1 MB
@aws-sdk/client-route53resolver 4.3 MB
@aws-sdk/client-s3 9.4 MB
@aws-sdk/client-s3-control 4.9 MB
@aws-sdk/client-s3outposts 371.5 kB
@aws-sdk/client-sagemaker 17.6 MB
@aws-sdk/client-sagemaker-a2i-runtime 565.7 kB
@aws-sdk/client-sagemaker-edge 252.0 kB
@aws-sdk/client-sagemaker-featurestore-runtime 429.4 kB
@aws-sdk/client-sagemaker-runtime 382.7 kB
@aws-sdk/client-savingsplans 818.2 kB
@aws-sdk/client-schemas 2.1 MB
@aws-sdk/client-secrets-manager 2.1 MB
@aws-sdk/client-securityhub 7.9 MB
@aws-sdk/client-serverlessapplicationrepository 1.3 MB
@aws-sdk/client-service-catalog 5.7 MB
@aws-sdk/client-service-catalog-appregistry 1.4 MB
@aws-sdk/client-service-quotas 1.5 MB
@aws-sdk/client-servicediscovery 2.1 MB
@aws-sdk/client-ses 4.9 MB
@aws-sdk/client-sesv2 5.5 MB
@aws-sdk/client-sfn 1.9 MB
@aws-sdk/client-shield 2.2 MB
@aws-sdk/client-signer 1.4 MB
@aws-sdk/client-sms 2.4 MB
@aws-sdk/client-snow-device-management 1.0 MB
@aws-sdk/client-snowball 1.9 MB
@aws-sdk/client-sns 2.8 MB
@aws-sdk/client-sqs 1.8 MB
@aws-sdk/client-ssm 11.2 MB
@aws-sdk/client-ssm-contacts 1.8 MB
@aws-sdk/client-ssm-incidents 2.1 MB
@aws-sdk/client-sso 462.1 kB
@aws-sdk/client-sso-admin 2.2 MB
@aws-sdk/client-sso-oidc 481.4 kB
@aws-sdk/client-storage-gateway 5.7 MB
@aws-sdk/client-sts 1.3 MB
@aws-sdk/client-support 1.3 MB
@aws-sdk/client-swf 3.8 MB
@aws-sdk/client-synthetics 1.1 MB
@aws-sdk/client-textract 1.0 MB
@aws-sdk/client-timestream-query 414.0 kB
@aws-sdk/client-timestream-write 1.1 MB
@aws-sdk/client-transcribe 2.9 MB
@aws-sdk/client-transcribe-streaming 3.2 MB
@aws-sdk/client-transfer 2.5 MB
@aws-sdk/client-translate 1.2 MB
@aws-sdk/client-waf 6.0 MB
@aws-sdk/client-waf-regional 6.3 MB
@aws-sdk/client-wafv2 3.9 MB
@aws-sdk/client-wellarchitected 2.3 MB
@aws-sdk/client-workdocs 2.9 MB
@aws-sdk/client-worklink 2.1 MB
@aws-sdk/client-workmail 3.4 MB
@aws-sdk/client-workmailmessageflow 333.1 kB
@aws-sdk/client-workspaces 3.4 MB
@aws-sdk/client-xray 2.1 MB
@aws-sdk/client-documentation-generator 136.6 kB

Describe the solution you'd like

Reduce the install size of the clients by taking the following steps:

  • Publish only the files in dist folders.
  • Remove comments from transpiled *.js files.
  • Strip comments from downleveled *.dts files.
  • Remove sourceMap files.

Example repo: https://github.com/trivikr/temp-client-s3

Additional context

This is a tracking issue for reducing publish size of clients.
Previous issues:

@trivikr trivikr added the feature-request New feature or enhancement. May require GitHub community feedback. label Sep 20, 2021
@trivikr trivikr changed the title Reduce install size of clients by removing unnecessary code from published tarball Reduce install size of clients by removing unnecessary files from published tarball Sep 20, 2021
@trivikr
Copy link
Member Author

trivikr commented Sep 20, 2021

Prior attempt in moving source files to src folder:

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request New feature or enhancement. May require GitHub community feedback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant