You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
compilers written in Rust and Go, since it literally doesn't have
263
+
to do anything except check some file stats and then hand the
264
+
cached results to Node. (In fact, since it caches in memory as
265
+
well as to disk, it might even be _faster_ in many cases than
266
+
running plain old JavaScript, if the program is large.)
267
+
268
+
And, this is with full type checking, which is sort of the point
269
+
of using TypeScript. No matter how fast your compiler is, if
270
+
you're then running `tsc --noEmit` to check your types, then it's
271
+
not actually gaining much.
272
+
273
+
If the daemon is _not_ running, and it's a cold start with no
274
+
cache, it's pretty slow, comparable with ts-node, especially if
275
+
type checking is enabled.
276
+
277
+
An exceptionally not scientific example comparison:
278
+
279
+
<prestyle="color:#eeeeee;background:#222222;position:relative"title="tapjs/tsimp main - tapjs/tsimp">
280
+
$ time node --loader @swc-node/register/esm hello.ts
281
+
(node:89220) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
282
+
--import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("%40swc-node/register/esm", pathToFileURL("./"));'
283
+
(Use `node --trace-warnings ...` to show where the warning was created)
284
+
hello, world
285
+
286
+
real 0m0.268s
287
+
user 0m0.255s
288
+
sys 0m0.033s
289
+
290
+
$ time node --import=tsx hello.ts
291
+
hello, world
292
+
293
+
real 0m0.135s
294
+
user 0m0.126s
295
+
sys 0m0.020s
296
+
297
+
$ time node --import=./dist/esm/hooks/import.mjs hello.ts
298
+
<spanstyle="color:#00ffff">hello.ts</span>:<spanstyle="color:#ffff00">2</span>:<spanstyle="color:#ffff00">18</span> - <spanstyle="color:#ff3030">error</span><spanstyle="color:#404040"> TS2322: </span>Type 'string' is not assignable to type 'boolean'.
299
+
300
+
<spanstyle="color:#222222;background:#eeeeee">2</span> const f: Foo = { bar: 'hello' }
</span> The expected type comes from property 'bar' which is declared here on type 'Foo'
307
+
308
+
hello, world
309
+
310
+
real 0m0.126s
311
+
user 0m0.110s
312
+
sys 0m0.022s
313
+
</pre>
314
+
315
+
## How is it so fast?
316
+
317
+

0 commit comments