Skip to content

Commit 545e31e

Browse files
authored
perf(ext): convert ext/io, ext/os, ext/net JS sources to lazy-loaded scripts (#33779)
## Summary Follow-up to #33760. Converts the ESM JS sources in `ext/io`, `ext/os`, and `ext/net` to IIFE-wrapped lazy-loaded scripts (`lazy_loaded_js`), eliminating ESM module resolution overhead. These three extensions have no cross-extension ESM import dependencies (only `core.loadExtScript` calls to already-converted extensions like `ext/web`), so no `internals` bridges are needed. Converting these also unblocks clean conversion of: - `ext/fs` (depends on `ext/io`) - `ext/fetch` (depends on `ext/net`)
1 parent 50a1af4 commit 545e31e

24 files changed

Lines changed: 68 additions & 48 deletions

File tree

cli/js/40_bench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
restorePermissions,
99
} from "ext:cli/40_test_common.js";
1010
const { Console } = core.loadExtScript("ext:deno_web/01_console.js");
11-
import { setExitHandler } from "ext:deno_os/30_os.js";
11+
const { setExitHandler } = core.loadExtScript("ext:deno_os/30_os.js");
1212
const {
1313
op_register_bench,
1414
op_bench_get_origin,

cli/js/40_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const {
3131
TypeError,
3232
} = primordials;
3333

34-
import { setExitHandler } from "ext:deno_os/30_os.js";
34+
const { setExitHandler } = core.loadExtScript("ext:deno_os/30_os.js");
3535

3636
// Capture `Deno` global so that users deleting or mangling it, won't
3737
// have impact on our sanitizers.

ext/fetch/22_http_client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import { core, primordials } from "ext:core/mod.js";
1414
import { op_fetch_custom_client } from "ext:core/ops";
15-
import { loadTlsKeyPair } from "ext:deno_net/02_tls.js";
15+
const { loadTlsKeyPair } = core.loadExtScript("ext:deno_net/02_tls.js");
1616

1717
const { internalRidSymbol } = core;
1818
const {

ext/fs/30_fs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ const {
9494
Uint32Array,
9595
} = primordials;
9696

97-
import { read, readSync, write, writeSync } from "ext:deno_io/12_io.js";
97+
const { read, readSync, write, writeSync } = core.loadExtScript(
98+
"ext:deno_io/12_io.js",
99+
);
98100
const abortSignal = core.loadExtScript("ext:deno_web/03_abort_signal.js");
99101
const {
100102
readableStreamForRid,

ext/http/00_serve.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ const {
7979
ReadableStreamPrototype,
8080
resourceForReadableStream,
8181
} = core.loadExtScript("ext:deno_web/06_streams.js");
82-
import {
82+
const {
8383
listen,
8484
listenOptionApiName,
8585
UpgradedConn,
86-
} from "ext:deno_net/01_net.js";
87-
import { hasTlsKeyPairOptions, listenTls } from "ext:deno_net/02_tls.js";
86+
} = core.loadExtScript("ext:deno_net/01_net.js");
87+
const { hasTlsKeyPairOptions, listenTls } = core.loadExtScript(
88+
"ext:deno_net/02_tls.js",
89+
);
8890
import {
8991
builtinTracer,
9092
ContextManager,

ext/io/12_io.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
2+
// deno-fmt-ignore-file
23

34
// Interfaces 100% copied from Go.
45
// Documentation liberally lifted from them too.
56
// Thank you! We love Go! <3
67

7-
import { core, primordials } from "ext:core/mod.js";
8-
import { op_set_raw } from "ext:core/ops";
8+
(function () {
9+
const { core, primordials } = globalThis.__bootstrap;
10+
const { op_set_raw } = core.ops;
911
const {
1012
Uint8Array,
1113
ArrayPrototypePush,
@@ -247,7 +249,7 @@ const stdin = new Stdin();
247249
const stdout = new Stdout();
248250
const stderr = new Stderr();
249251

250-
export {
252+
return {
251253
read,
252254
readAll,
253255
readAllSync,
@@ -266,3 +268,4 @@ export {
266268
write,
267269
writeSync,
268270
};
271+
})()

ext/io/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn stdio_fd(fd: i32) -> StdFile {
210210

211211
deno_core::extension!(deno_io,
212212
deps = [ deno_web ],
213-
esm = [ "12_io.js" ],
213+
lazy_loaded_js = [ "12_io.js" ],
214214
options = {
215215
stdio: Option<Stdio>,
216216
},

ext/net/01_net.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
2+
// deno-fmt-ignore-file
23

3-
import { core, primordials } from "ext:core/mod.js";
4+
(function () {
5+
const { core, primordials } = globalThis.__bootstrap;
46
const {
57
BadResourcePrototype,
68
InterruptedPrototype,
79
internalRidSymbol,
810
internalFdSymbol,
911
createCancelHandle,
1012
} = core;
11-
import {
13+
const {
1214
op_dns_resolve,
1315
op_net_accept_tcp,
1416
op_net_accept_tunnel,
@@ -34,7 +36,7 @@ import {
3436
op_net_set_multi_ttl_udp,
3537
op_set_keepalive,
3638
op_set_nodelay,
37-
} from "ext:core/ops";
39+
} = core.ops;
3840
const UDP_DGRAM_MAXSIZE = 65507;
3941

4042
const {
@@ -741,7 +743,7 @@ async function connect(args) {
741743
}
742744
}
743745

744-
export {
746+
return {
745747
Conn,
746748
connect,
747749
createListenDatagram,
@@ -759,3 +761,4 @@ export {
759761
validatePort,
760762
VsockConn,
761763
};
764+
})()

ext/net/02_tls.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Copyright 2018-2026 the Deno authors. MIT license.
2+
// deno-fmt-ignore-file
23

3-
import { core, internals, primordials } from "ext:core/mod.js";
4+
(function () {
5+
const { core, internals, primordials } = globalThis.__bootstrap;
46
const { internalRidSymbol } = core;
5-
import {
7+
const {
68
op_net_accept_tls,
79
op_net_connect_tls,
810
op_net_listen_tls,
@@ -15,15 +17,15 @@ import {
1517
op_tls_key_static,
1618
op_tls_peer_certificate,
1719
op_tls_start,
18-
} from "ext:core/ops";
20+
} = core.ops;
1921
const {
2022
ObjectDefineProperty,
2123
TypeError,
2224
Symbol,
2325
SymbolFor,
2426
} = primordials;
2527

26-
import { Conn, Listener, validatePort } from "ext:deno_net/01_net.js";
28+
const { Conn, Listener, validatePort } = core.loadExtScript("ext:deno_net/01_net.js");
2729

2830
const _getPeerCertificate = Symbol("getPeerCertificate");
2931

@@ -255,7 +257,7 @@ internals.serverNameSymbol = serverNameSymbol;
255257
internals.createTlsKeyResolver = createTlsKeyResolver;
256258
internals.getPeerCertificate = _getPeerCertificate;
257259

258-
export {
260+
return {
259261
connectTls,
260262
hasTlsKeyPairOptions,
261263
listenTls,
@@ -265,3 +267,4 @@ export {
265267
TlsConn,
266268
TlsListener,
267269
};
270+
})()

ext/net/03_quic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const {
4545
WritableStream,
4646
writableStreamForRid,
4747
} = core.loadExtScript("ext:deno_web/06_streams.js");
48-
import { loadTlsKeyPair } from "ext:deno_net/02_tls.js";
48+
const { loadTlsKeyPair } = core.loadExtScript("ext:deno_net/02_tls.js");
4949
const {
5050
BadResourcePrototype,
5151
} = core;

0 commit comments

Comments
 (0)