Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

(question) possible to reduce size of package + dependencies? #3

Closed
doc-l opened this issue Sep 19, 2020 · 4 comments
Closed

(question) possible to reduce size of package + dependencies? #3

doc-l opened this issue Sep 19, 2020 · 4 comments

Comments

@doc-l
Copy link

doc-l commented Sep 19, 2020

First of all great work on this SDK! It's super easy, works great. I have set it up in an AWS Lambda serverless function, which also works (yay for serverless blockchain communication!), but the package size is quite big: almost 50MB zipped. The AWS Lambda limit is exactly 50MB zipped, so it barely fits inside a Lambda function. However, when you need a couple more dependencies you already have a problem. This is probably due to gRPC and its many many subdependencies.

Would it be possible to create a minimal version, check if all dependencies are really needed or something so the package size can be decreased?

Thanks!

@kikengineering
Copy link
Contributor

There seems to be some decent wins that can be done by separating out a few of the agora-api dependencies into dev only dependencies.

The two biggest culprits seem to be grpc and sodium-native. The former I think we're somewhat stuck using for now. The latter, at least taking a peak locally, seems to be largely driven by the intermediate build objects. sodium-native is currently used (transitively) by stellar-base.

We can poke around a bit with the npm dependency / build system to try and make sodium-native more manageable.

@kikengineering
Copy link
Contributor

Perhaps as mentioned in #2 (comment), we can just remove sodium-native as a dependency, and let consumers decide whether or not they want to pull the dependency in.

@kikengineering
Copy link
Contributor

The agora-api changes have been pulled in to kin-sdk-v2@0.2.2 (a3f8314).

As for sodium-native, a comment has been added to the readme indicating it can be safely removed (at the cost of some performance). Running the following steps now produces a zipped node_modules that is about ~24 MiB:

  1. npm i --production
  2. rm -rf node_modules/sodium-native
  3. zip modules.zip node_modules

Let us know if this is sufficient for you use cases.

@doc-l
Copy link
Author

doc-l commented Sep 23, 2020

Thanks a lot, this works! The package size now decreased to around 35MB instead of 49MB. This gives plenty of room for other stuff. It's still quite big, but I guess gRPC is quite heavy as well.

By the way, if you use serverless and the serverless-webpack plugin, you can get it working easily by adding this in serverless.yml:

custom:
  webpack:
    packager: 'yarn'
    packagerOptions:
      scripts:
        - rm -rf node_modules/grpc/src/node/extension_binary/* # Remove grpc for other systems
        - rm -rf node_modules/sodium-native
        - npm rebuild grpc --target=12.0.0 --target_arch=x64 --target_platform=linux --target_libc=glibc # add grpc for node lambda env
    includeModules:
      forceExclude:
        - aws-sdk

@doc-l doc-l closed this as completed Sep 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants