summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-10-25 11:00:14 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-11-05 13:26:54 -0800
commitb3400d822f6e9a1100e693cc06cd09c8249d4422 (patch)
treec93f4119d3e911f6201b827b13c1f7528f8892a7 /js
parent27ecfc1617c79d23255e025fcbd0257b3523906a (diff)
Decode main.js.map during snapshotting.
Pro: time ./out/debug/deno tests/error_001.ts 3.0s -> 0.4s Con: time ./tool/build.py snapshot 33s -> 1m52s out/debug/gen/snapshot_deno.bin 39M -> 121M
Diffstat (limited to 'js')
-rw-r--r--js/compiler.ts6
-rw-r--r--js/main.ts5
-rw-r--r--js/v8_source_maps.ts9
3 files changed, 14 insertions, 6 deletions
diff --git a/js/compiler.ts b/js/compiler.ts
index 941691f5c..a6b6e6970 100644
--- a/js/compiler.ts
+++ b/js/compiler.ts
@@ -388,6 +388,7 @@ export class DenoCompiler
let lastModule: ModuleMetaData | undefined;
sourceMaps.install({
installPrepareStackTrace: true,
+
getGeneratedContents: (fileName: string): string | RawSourceMap => {
this._log("compiler.getGeneratedContents", fileName);
if (fileName === "gen/bundle/main.js") {
@@ -419,6 +420,11 @@ export class DenoCompiler
}
}
});
+ // Pre-compute source maps for main.js.map. This will happen at compile-time
+ // as long as Compiler is instanciated before the snapshot is created..
+ const consumer = sourceMaps.loadConsumer("gen/bundle/main.js");
+ assert(consumer != null);
+ consumer!.computeColumnSpans();
}
private constructor() {
diff --git a/js/main.ts b/js/main.ts
index 0ed45aaec..02e5dcb4d 100644
--- a/js/main.ts
+++ b/js/main.ts
@@ -11,6 +11,10 @@ import { promiseErrorExaminer, promiseRejectHandler } from "./promise_util";
import { replLoop } from "./repl";
import { version } from "typescript";
+// Instantiate compiler at the top-level so it decodes source maps for the main
+// bundle during snapshot.
+const compiler = DenoCompiler.instance();
+
function sendStart(): msg.StartRes {
const builder = flatbuffers.createBuilder();
msg.Start.startStart(builder);
@@ -44,7 +48,6 @@ export default function denoMain() {
libdeno.setGlobalErrorHandler(onGlobalError);
libdeno.setPromiseRejectHandler(promiseRejectHandler);
libdeno.setPromiseErrorExaminer(promiseErrorExaminer);
- const compiler = DenoCompiler.instance();
// 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
diff --git a/js/v8_source_maps.ts b/js/v8_source_maps.ts
index f73cc2d38..cd61955d2 100644
--- a/js/v8_source_maps.ts
+++ b/js/v8_source_maps.ts
@@ -186,7 +186,7 @@ function CallSiteToString(frame: CallSite): string {
// Regex for detecting source maps
const reSourceMap = /^data:application\/json[^,]+base64,/;
-function loadConsumer(source: string): SourceMapConsumer | null {
+export function loadConsumer(source: string): SourceMapConsumer | null {
let consumer = consumers.get(source);
if (consumer == null) {
const code = getGeneratedContents(source);
@@ -210,8 +210,8 @@ function loadConsumer(source: string): SourceMapConsumer | null {
sourceMapData = arrayToStr(ui8);
sourceMappingURL = source;
} else {
- // Support source map URLs relative to the source URL
- //sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
+ // TODO Support source map URLs relative to the source URL
+ // sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
sourceMapData = getGeneratedContents(sourceMappingURL);
}
@@ -219,7 +219,6 @@ function loadConsumer(source: string): SourceMapConsumer | null {
typeof sourceMapData === "string"
? JSON.parse(sourceMapData)
: sourceMapData;
- //console.log("sourceMapData", sourceMapData);
consumer = new SourceMapConsumer(rawSourceMap);
consumers.set(source, consumer);
}
@@ -242,7 +241,7 @@ function retrieveSourceMapURL(fileData: string): string | null {
return lastMatch[1];
}
-function mapSourcePosition(position: Position): MappedPosition {
+export function mapSourcePosition(position: Position): MappedPosition {
const consumer = loadConsumer(position.source);
if (consumer == null) {
return position;