Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excessively long print times #38

Open
tjjfvi opened this issue Jan 19, 2022 · 0 comments
Open

Excessively long print times #38

tjjfvi opened this issue Jan 19, 2022 · 0 comments

Comments

@tjjfvi
Copy link

tjjfvi commented Jan 19, 2022

Here's a small benchmark to demonstrate the issue:

processing file https://cdn.esm.sh/v63/[email protected]/es2021/lodash.js:
    fetching...
        fetch: 151ms
        fetched size: 73KB
    transforming...
        transform: 632ms
        transformed size: 151KB
    parsing...
        parse: 192ms
        parsed size: 3236KB
    printing...
        print: 1949ms
        printed size: 145KB

processing file https://cdn.esm.sh/v63/[email protected]/es2021/typescript.js:
    fetching...
        fetch: 270ms
        fetched size: 3368KB
    transforming...
        transform: 4601ms
        transformed size: 5649KB
    parsing...
        parse: 2317ms
        parsed size: 92196KB
    printing...
        print: 1302059ms
        printed size: 5620KB
Benchmark Source
import { parse, print, transform } from "https://deno.land/x/swc/mod.ts";

for (
  let file of [
    "https://cdn.esm.sh/v63/[email protected]/es2021/lodash.js",
    "https://cdn.esm.sh/v63/[email protected]/es2021/typescript.js",
  ]
) {
  console.group(`\nprocessing file ${file}:`);

  console.group("fetching...");
  console.time("fetch");
  let fetched = await fetch(file).then((r) => r.text());
  console.timeEnd("fetch");
  printFileReport("fetched", fetched);
  console.groupEnd();

  console.group("transforming...");
  console.time("transform");
  let transformed = transform(fetched, {}).code;
  console.timeEnd("transform");
  printFileReport("transformed", transformed);
  console.groupEnd();

  console.group("parsing...");
  console.time("parse");
  let program = parse(fetched, { syntax: "ecmascript" });
  console.timeEnd("parse");
  printFileReport("parsed", JSON.stringify(program));
  console.groupEnd();

  console.group("printing...");
  console.time("print");
  let printed = print(program, {}).code;
  console.timeEnd("print");
  printFileReport("printed", printed);
  console.groupEnd();

  console.groupEnd();
}

function printFileReport(name: string, file: string) {
  console.log(`${name} size: ${file.length / 1e3 | 0}KB`);
}

Note that the print time for typescript.js is over 20 minutes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant