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

Update imports syntax in v0.x to reduce cold start duration #16

Open
Eikix opened this issue Apr 28, 2022 · 2 comments
Open

Update imports syntax in v0.x to reduce cold start duration #16

Eikix opened this issue Apr 28, 2022 · 2 comments

Comments

@Eikix
Copy link

Eikix commented Apr 28, 2022

Context: aws-sdk v2 uses cjs and thus does not tree shake. This means that the following syntax:
import type { EventBridge } from 'aws-sdk'; will result in importing aws-sdk package in its entirety, rather than just EventBridge type.

Note that this is fixed in aws-sdk v3.

Impact: Increasing cold starts for lambdas (up to +1.3s on cold start duration).
How? For instance, a lambda uses this package (v0.7) when sending an event to EventBridge.

Proposed fix: In versions < 1, adopt the following import syntax:
import type EventBridge from 'aws-sdk/EventBridge';

Thanks:)

@fredericbarthelet
Copy link
Owner

fredericbarthelet commented Apr 28, 2022

Hi @Eikix and thanks for the proposal :)

I believe import type statements are stripped altogether at compilation by Typescript, and are therefore not used during bundling phase. You can learn more about this in https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html. That's why aws-sdk is not part of this library at all, and solely used as a dev dependency in order to run tests on the actual implementation.

However, you should indeed in your lambda implementation using typebridge make sure to instantiate EventBridge client using import EventBridge from 'aws-sdk/EventBridge';

Did you see some problem in bundling even implementing SDK client import as described above ?

@Eikix
Copy link
Author

Eikix commented Apr 29, 2022

Hi @fredericbarthelet ! Thank you for your time. You're absolutely right, thanks for pointing this out:).

PS: I'm sure you meant import EventBridge from 'aws-sdk/clients/eventbridge';

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

No branches or pull requests

2 participants