Skip to content

Commit

Permalink
let's try --experimental-strip-types
Browse files Browse the repository at this point in the history
  • Loading branch information
doehyunbaek committed Aug 7, 2024
1 parent 635f16d commit 45b04b3
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wasm-r3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '21.x'
node-version: '22.6.x'
- run: npm install && npx playwright install
- name: Download Binaryen
run: |
Expand Down
22 changes: 12 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"name": "tool",
"module": "index.ts",
"type": "module",
"devDependencies": {
"@types/diff": "^5.0.8",
Expand All @@ -19,15 +17,14 @@
"dependencies": {
"acorn": "^8.11.2",
"command-line-args": "^5.2.1",
"playwright": "^1.42.1",
"playwright": "^1.46.0",
"ws": "^8.17.1"
},
"scripts": {
"start": "npm run build && node ./dist/src/cli/main.cjs",
"test": "npm run build && node --experimental-wasm-multi-memory --experimental-wasm-typed_funcref --experimental-wasm-gc ./dist/tests/test-wasm-r3.cjs",
"build": "npm run build-rust && npm run build-wasabi && tsc",
"start": "node --experimental-strip-types ./src/start.ts",
"test": "node --experimental-strip-types ./src/test.ts",
"build": "npm run build-rust && npm run build-wasabi",
"build-rust": "cd crates && cargo build --release && cd -",
"build-wasabi": "cd wasabi/crates/wasabi_js && npm run build && wasm-pack build --target web && wasm-pack build --target nodejs --out-dir ../../../dist/wasabi && cd ../../..",
"build-binaryen": "cd binaryen && git submodule update --init && cmake . && make"
"build-wasabi": "cd wasabi/crates/wasabi_js && npm run build && wasm-pack build --target web && cd ../../.."
}
}
File renamed without changes.
5 changes: 2 additions & 3 deletions src/main.cts → src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ async function main() {
}

export default async function run(url: string, options: Options) {
let analyser: AnalyserI
analyser = new Analyser('./dist/src/tracer.cjs', options)
let analyser = new Analyser('./dist/src/tracer.cjs', options)
await analyser.start(url, { headless: options.headless })
await askQuestion(`Record is running. Enter 'Stop' to stop recording: `)
console.log(`Record stopped. Downloading...`)
Expand All @@ -18,7 +17,7 @@ export default async function run(url: string, options: Options) {

import commandLineArgs from 'command-line-args'
import fs from 'fs'
import Benchmark, { AnalyserI, Analyser } from './web.cjs'
import Benchmark, { Analyser } from './web.ts'

export type Options = {
headless: boolean,
Expand Down
2 changes: 1 addition & 1 deletion tests/test-slice-dice.cts → src/test-slice-dice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { exit } from "process";
import { Server } from "http";
import path from "path";
import { execSync } from "child_process";
import Benchmark, { Analyser } from "../src/web.cjs";
import Benchmark, { Analyser } from "./web.ts";

export default async function runSliceDiceTests(names: string[], options) {
for (let name of names) {
Expand Down
33 changes: 28 additions & 5 deletions tests/test-wasm-r3.cts → src/test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import fs from "fs/promises";
import path from "path";
import express from "express";
//@ts-ignore
import { Server } from "http";
import commandLineArgs from "command-line-args";
import { getDirectoryNames, trimFromLastOccurance, writeWithSpaces } from "./test-utils.cjs";
import { filter } from "../src/filter.cjs";
import runSliceDiceTests from "./test-slice-dice.cjs";
import Benchmark, { Analyser } from "../src/web.cjs";
import { execSync } from "child_process";
import { filter } from "./filter.ts";
import Benchmark, { Analyser } from "./web.ts";
import runSliceDiceTests from "./test-slice-dice.ts";

type Success = { success: true };
type Failure = { success: false };
Expand Down Expand Up @@ -149,4 +147,29 @@ async function startServer(websitePath: string): Promise<[Server, string]> {
const url = `http://localhost:${address.port}`;

return [server, url]
}

export async function getDirectoryNames(folderPath: string) {
const entries = await fs.readdir(folderPath, { withFileTypes: true });

const directories: string[] = entries
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name);

return directories;
}

export async function delay(ms: number) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}

export function trimFromLastOccurance(str: string, substring: string) {
const lastIndex = str.lastIndexOf(substring);
if (lastIndex === -1) {
// Substring not found, return original string or handle as needed
return str;
}
return str.substring(0, lastIndex + substring.length);
}
26 changes: 4 additions & 22 deletions src/web.cts → src/web.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import { Browser, chromium, firefox, Frame, Page, webkit, Worker } from 'playwright'
import fs from 'fs/promises'
import acorn from 'acorn'
import { trimFromLastOccurance } from '../tests/test-utils.cjs'

// read port from env
const CDP_PORT = process.env.CDP_PORT || 8080

export interface AnalyserI {
start: (url: string, options: { headless: boolean }) => Promise<Page>
stop: () => Promise<AnalysisResult>
}

export type AnalysisResult = {
result: string,
wasm: number[]
}[]

type Options = { extended?: boolean, noRecord?: boolean, evalRecord?: boolean, firefox?: boolean, webkit?: boolean }
export class Analyser implements AnalyserI {
export class Analyser {

private analysisPath: string
private options: Options
Expand Down Expand Up @@ -125,7 +117,6 @@ export class Analyser implements AnalyserI {
}
const script = await response.text()
try {
acorn.parse(script, { ecmaVersion: 'latest' })
const body = `${initScript}${script}`
await route.fulfill({ response, body: body })
} catch {
Expand Down Expand Up @@ -196,8 +187,9 @@ export class Analyser implements AnalyserI {
import fss from 'fs'
import path from 'path'
import { execSync } from 'child_process';
//@ts-ignore
import { instrument_wasm } from '../wasabi/wasabi_js.js'
import { trimFromLastOccurance } from './test.ts'
import { firefox, webkit, chromium } from 'playwright'
import type { Browser, Frame, Worker, Page} from 'playwright'

export type Record = { binary: number[], trace: string }[]

Expand All @@ -208,8 +200,6 @@ type WasabiRuntime = string[]
export default class Benchmark {

private record: Record
private constructor() { }

async save(benchmarkPath: string, options) {
// await new Promise(resolve => setTimeout(resolve, 10 * 60 * 1000));
if (!fss.existsSync(benchmarkPath)) await fs.mkdir(benchmarkPath, { recursive: true })
Expand Down Expand Up @@ -237,14 +227,6 @@ export default class Benchmark {
return this.record.map(r => r.binary)
}

instrumentBinaries(): WasabiRuntime[] {
return this.record.map((r, i) => {
const { instrumented, js } = instrument_wasm(r.binary)
this.record[i].binary = instrumented
return js
})
}

getRecord() {
return this.record
}
Expand Down
82 changes: 0 additions & 82 deletions tests/test-utils.cts

This file was deleted.

2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"target": "ES2022",
"sourceMap": true,
"outDir": "./dist",
"noEmit": true,
"allowImportingTsExtensions": true,
// "composite": true,
},
"include": [
Expand Down

0 comments on commit 45b04b3

Please sign in to comment.