Commit ef6e5b1
authored
feat: faster, lazy-friendly runtime loading (#4181)
Instead of eagerly loading each type from the assemblies in order to annotate the constructors with jsii fully qualified type names (FQNs), leverage the `jsii.rtti` data that is injected by the `jsii` compiler since release `1.19.0`.
This should make the jsii runtimes friendlier to large libraries that include lazy-loading provisions, such as the `aws-cdk-lib`.
---
In addition to this, `JSII_RUNTIME_PACKAGE_CACHE` was flipped from opt-in to opt-out (set it to any value other than `enabled` to disable), and the `@jsii/runtime` entry point now sets `--preserve-symlinks` so that we can symbolically link packages from the cache instead of copying them around, which is significantly faster.
---
Finally, the jsii kernel had not opted out of the assembly validation feature, which is redundant in the majority of scenarios, and is quite time-consuming (~500ms for `aws-cdk-lib`)... So also opting out, but allowing users to opt-back-in via an environment variable.
---
Example on a "simple" repro via `aws-cdk-lib`:
Before:
```
[@jsii/kernel:timing] tar.extract(<redacted>/.venv-vanilla/lib/python3.11/site-packages/aws_cdk/_jsii/[email protected]) => <redacted>/jsii-kernel-Xxp43L/node_modules/aws-cdk-lib: 1.909s
[@jsii/kernel:timing] loadAssemblyFromPath(<redacted>/jsii-kernel-Xxp43L/node_modules/aws-cdk-lib): 383.8ms
[@jsii/kernel:timing] require(<redacted>/jsii-kernel-Xxp43L/node_modules/aws-cdk-lib): 630.081ms
[@jsii/kernel:timing] registerAssembly({ name: aws-cdk-lib, types: 10957 }): 8.452ms
[@jsii/kernel:timing] load({
"name": "aws-cdk-lib",
"version": "2.87.0",
"tarball": "<redacted>/.venv-vanilla/lib/python3.11/site-packages/aws_cdk/_jsii/[email protected]",
"api": "load"
}): 2.933s
```
After:
```
[@jsii/kernel:timing] tar.extract(<redacted>/.venv-lazy/lib/python3.11/site-packages/aws_cdk/_jsii/[email protected]) => <redacted>/jsii-kernel-eAOMah/node_modules/aws-cdk-lib: 12.247ms
[@jsii/kernel:timing] loadAssemblyFromPath(<redacted>/jsii-kernel-eAOMah/node_modules/aws-cdk-lib): 388.388ms
[@jsii/kernel:timing] require(<redacted>/jsii-kernel-eAOMah/node_modules/aws-cdk-lib/lazy-index.js): 132.801ms
[@jsii/kernel:timing] registerAssembly({ name: aws-cdk-lib, types: 10957 }): 0.009ms
[@jsii/kernel:timing] load({
"name": "aws-cdk-lib",
"version": "2.87.0",
"tarball": "<redacted>/.venv-lazy/lib/python3.11/site-packages/aws_cdk/_jsii/[email protected]",
"api": "load"
}): 537.449ms
```
---
By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license].
[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.01 parent cde3db6 commit ef6e5b1
File tree
23 files changed
+687
-160
lines changed- packages
- @jsii
- kernel/src
- tar-cache
- python-runtime/src/jsii/_kernel/providers
- runtime
- bin
- lib
- @scope/jsii-calc-lib
- lib
- test
- jsii-pacmak/test/generated-code/__snapshots__
- jsii-reflect/test/__snapshots__
- jsii-rosetta/test/jsii
23 files changed
+687
-160
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
92 | 157 | | |
93 | 158 | | |
94 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
69 | 73 | | |
70 | 74 | | |
71 | 75 | | |
| 76 | + | |
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
| |||
147 | 152 | | |
148 | 153 | | |
149 | 154 | | |
150 | | - | |
| 155 | + | |
151 | 156 | | |
152 | 157 | | |
153 | | - | |
| 158 | + | |
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
| |||
159 | 164 | | |
160 | 165 | | |
161 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
162 | 172 | | |
163 | 173 | | |
164 | | - | |
165 | | - | |
| 174 | + | |
| 175 | + | |
166 | 176 | | |
167 | 177 | | |
168 | 178 | | |
| |||
333 | 343 | | |
334 | 344 | | |
335 | 345 | | |
336 | | - | |
| 346 | + | |
337 | 347 | | |
338 | 348 | | |
339 | 349 | | |
| |||
420 | 430 | | |
421 | 431 | | |
422 | 432 | | |
423 | | - | |
| 433 | + | |
424 | 434 | | |
425 | 435 | | |
426 | 436 | | |
| |||
568 | 578 | | |
569 | 579 | | |
570 | 580 | | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
571 | 596 | | |
572 | 597 | | |
573 | 598 | | |
| |||
869 | 894 | | |
870 | 895 | | |
871 | 896 | | |
872 | | - | |
| 897 | + | |
873 | 898 | | |
874 | 899 | | |
875 | 900 | | |
| |||
1029 | 1054 | | |
1030 | 1055 | | |
1031 | 1056 | | |
1032 | | - | |
| 1057 | + | |
1033 | 1058 | | |
1034 | 1059 | | |
1035 | 1060 | | |
| |||
1047 | 1072 | | |
1048 | 1073 | | |
1049 | 1074 | | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
1050 | 1095 | | |
1051 | 1096 | | |
1052 | 1097 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
3 | 17 | | |
4 | 18 | | |
5 | 19 | | |
| |||
9 | 23 | | |
10 | 24 | | |
11 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
12 | 32 | | |
13 | 33 | | |
14 | 34 | | |
| |||
0 commit comments