Repository navigation
Commit faffce0
authored
feat(aws-cdk-lib): reduce load time of JavaScript library (#27217)
This change halves the load time of `require('aws-cdk-lib')`, from ~600ms to ~300ms on my machine. It also shaves ~8min off running all integ tests (again, on my machine).
It does this by making all loading of JavaScript modules lazy, so they are only loaded just before any symbols from them are actually accessed (instead of loading all modules at startup). This new automatic module replaces the previous manual effort to do something similar, in `lazy-index.ts`.
Note that this transformation (unfortunately) does not affect TypeScript compilation times: the TypeScript compiler is still going to read all `.d.ts` files. To improve interactive TypeScript performance, use `swc` or `ts-node` with type checking disabled. Fully type checking your application using `tsc` will take the amount of time it takes.
## What's the big idea?
Turning this:
```js
const x = require("x");
module.exports.banana = function() {
return x.hello();
}
```
Into this:
```js
var x = () => { var tmp = require("x"); x = () => tmp; return tmp; };
module.exports.banana = function () {
return x().hello();
};
```
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*1 parent 1be9894 commit faffce0
32 files changed
Lines changed: 798 additions & 287 deletions
File tree
- packages
- @aws-cdk-testing/cli-integ/tests/init-javascript
- aws-cdk-lib
- aws-ec2/lib/restrict-default-security-group-handler
- aws-iam/lib/oidc-provider
- aws-lambda/test
- docker-build-lambda
- aws-logs/lib/log-retention-provider
- aws-route53/lib
- cross-account-zone-delegation-handler
- delete-existing-record-set-handler
- aws-ses/lib/drop-spam-handler
- aws-stepfunctions-tasks/lib/eval-nodejs-handler
- core/lib
- custom-resource-provider
- private/cfn-utils-provider
- pipelines/lib/private/approve-lambda
- scripts
- triggers/lib/lambda
- tools/@aws-cdk/lazify
- bin
- lib
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
Whitespace-only changes.
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
443 | | - | |
| 443 | + | |
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
| |||
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
Whitespace-only changes.
0 commit comments