floydspace / effect-aws

🚰 Effectful AWS
https://floydspace.github.io/effect-aws/
MIT License
49 stars 4 forks source link

tree-shaking #28

Closed godu closed 9 months ago

godu commented 9 months ago

I was surprise that a simple program produces a ~500kb bundle

import {Effect} from 'effect';
import {DynamoDBService} from '@effect-aws/client-dynamodb';

const {listTables} = Effect.serviceFunctions(DynamoDBService);

export const program = listTables({});

bundled with

esbuild ./src/index.ts --bundle "--external:@aws-sdk/*" --outfile=./dist/index.js --metafile=./dist/meta.json

Maybe we should improve the tree-shacking readiness.

godu commented 9 months ago

Perhaps we could disable the "sideEffects" property in the package.json (cf https://webpack.js.org/guides/tree-shaking/).

I test it, and the bundle passes from 570.9kb to 458.2kb.

floydspace commented 9 months ago

oh, wow, didn't know about this property, I tried me end project and indeed reduced size in like twice. however when I tried to add it in the @effect-aws packages, I didn't see any improvements is it supposed to be used in libs?

floydspace commented 9 months ago

I was surprise that a simple program produces a ~500kb bundle

image

I cannot reproduce it I'm using command

esbuild --bundle src/lambda.ts --target=\"node18\" --platform=\"node\" --outfile=\"dist/index.js\" --tsconfig=\"tsconfig.json\" --tree-shaking=true --main-fields=module,main --minify --metafile=dist/meta.json

probably you can try this --main-fields=module,main in your esbuild command, it should improve tree shaking

godu commented 9 months ago

Ok, I have a hint. In my sample, I don't use the DefaultDynamoDBServiceLayer and esbuild should be able to prune the ../../node_modules/@effect-aws/client-dynamodb/lib/esm/DynamoDBService.js file.

Without the sideEffects property, the DynamoDBService module is present in my bundle, even if I use any your recommended flags.

I think it will be more safe to add "sideEffects": [] like effect does (cf: https://discord.com/channels/795981131316985866/1174418279276757002/1174680724377440356).

floydspace commented 9 months ago

agreed. If you feel like you can raise a PR, or I will pick it up in the evening.