From ee9c627cc5f92898d104e9359059b57354c9f83c Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Tue, 29 Jan 2019 11:41:28 +1000 Subject: Split out compiler snapshot (#1566) Speeds up startup time, reduces runtime heap size. --- js/os.ts | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'js/os.ts') diff --git a/js/os.ts b/js/os.ts index bbb4d0569..36093c32c 100644 --- a/js/os.ts +++ b/js/os.ts @@ -1,9 +1,10 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import * as msg from "gen/msg_generated"; +import { handleAsyncMsgFromRust, sendSync } from "./dispatch"; +import * as flatbuffers from "./flatbuffers"; +import { libdeno } from "./libdeno"; import { assert } from "./util"; import * as util from "./util"; -import * as flatbuffers from "./flatbuffers"; -import { sendSync } from "./dispatch"; /** process id */ export let pid: number; @@ -142,3 +143,32 @@ export function env(): { [index: string]: string } { // TypeScript cannot track assertion above, therefore not null assertion return createEnv(res); } + +/** Send to the privileged side that we have setup and are ready. */ +function sendStart(): msg.StartRes { + const builder = flatbuffers.createBuilder(); + msg.Start.startStart(builder); + const startOffset = msg.Start.endStart(builder); + const baseRes = sendSync(builder, msg.Any.Start, startOffset); + assert(baseRes != null); + assert(msg.Any.StartRes === baseRes!.innerType()); + const startResMsg = new msg.StartRes(); + assert(baseRes!.inner(startResMsg) != null); + return startResMsg; +} + +// This function bootstraps an environment within Deno, it is shared both by +// the runtime and the compiler environments. +// @internal +export function start(): msg.StartRes { + libdeno.recv(handleAsyncMsgFromRust); + + // First we send an empty `Start` message to let the privileged side know we + // are ready. The response should be a `StartRes` message containing the CLI + // args and other info. + const startResMsg = sendStart(); + + util.setLogDebug(startResMsg.debugFlag()); + + return startResMsg; +} -- cgit v1.2.3