Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7b51b30
adding files
camillobruni Aug 7, 2025
0dc1c0a
adding more
camillobruni Aug 7, 2025
c1cc62d
wip
camillobruni Aug 7, 2025
a8ef519
fix
camillobruni Aug 7, 2025
96b1bd0
add
camillobruni Aug 7, 2025
899976a
add sources
camillobruni Aug 7, 2025
00b3823
adding files
camillobruni Aug 7, 2025
62a0a93
wup
camillobruni Aug 8, 2025
b570cd0
wip
camillobruni Aug 8, 2025
46b5497
use importer class
camillobruni Aug 8, 2025
83c5ce8
wip
camillobruni Aug 8, 2025
5d4640f
adding more files
camillobruni Aug 8, 2025
c5d1b78
adding more files
camillobruni Aug 8, 2025
6d924f8
fixes
camillobruni Aug 8, 2025
9a3c26c
adding more
camillobruni Aug 8, 2025
52bb2d9
adding gen files
camillobruni Aug 8, 2025
843977d
adding project files
camillobruni Aug 8, 2025
91245d4
fix
camillobruni Aug 8, 2025
78964f2
addin gdist fiels
camillobruni Aug 8, 2025
43bb5d0
adding benchmark
camillobruni Aug 8, 2025
ad6a881
lowercase fs names
camillobruni Aug 8, 2025
0038ac1
better import script handling tsconfig extends
camillobruni Aug 8, 2025
0ab3fb9
update
camillobruni Aug 8, 2025
e814985
adding files
camillobruni Aug 8, 2025
f3d0085
moving files
camillobruni Aug 8, 2025
5046d81
Merge branch 'main' into 2025-08-07_typescript
camillobruni Aug 8, 2025
73b4c37
updateing
camillobruni Aug 8, 2025
7138ae7
Merge branch 'main' into 2025-08-07_typescript
camillobruni Aug 14, 2025
8e34764
fix workload
camillobruni Aug 14, 2025
2b2e28b
Merge branch 'main' into 2025-08-07_typescript
camillobruni Aug 15, 2025
ff3ecbe
adding readme
camillobruni Aug 20, 2025
da41425
convert to esm
camillobruni Aug 20, 2025
4208f0c
adding license header.
camillobruni Aug 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1813,7 +1813,7 @@ let BENCHMARKS = [
tags: ["Default", "Octane"],
}),
new DefaultBenchmark({
name: "typescript",
name: "typescript-octane",
files: [
"./Octane/typescript-compiler.js",
"./Octane/typescript-input.js",
Expand All @@ -1822,7 +1822,7 @@ let BENCHMARKS = [
iterations: 15,
worstCaseCount: 2,
deterministicRandom: true,
tags: ["Default", "Octane"],
tags: ["Default", "Octane", "typescript"],
}),
// RexBench
new DefaultBenchmark({
Expand Down Expand Up @@ -2039,6 +2039,17 @@ let BENCHMARKS = [
],
tags: ["Default", "ClassFields"],
}),
new DefaultBenchmark({
name: "typescript-lib",
files: [
"./TypeScript/src/mock/sys.js",
"./TypeScript/dist/typescript-compile-test.js",
"./TypeScript/benchmark.js",
],
iterations: 3,
worstCaseCount: 2,
tags: ["Default", "typescript"],
}),
// Generators
new AsyncBenchmark({
name: "async-fs",
Expand Down
2 changes: 2 additions & 0 deletions TypeScript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build/*.git
17 changes: 17 additions & 0 deletions TypeScript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# TypeSCript test for JetStream

Measures the performance of running typescript on several framwork sources.

The build steps bundles sources from different frameworks:
- [jestjs](https://github.com/jestjs/jest.git)
- [zod](https://github.com/colinhacks/zod.git)
- [immer](https://github.com/immerjs/immer.git)

## Build Instructions

```bash
# install required node packages.
npm ci
# build the workload, output is ./dist
npm run build
```
33 changes: 33 additions & 0 deletions TypeScript/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// Prevent typescript logging output.
console.log = () => {};

class Benchmark {
runIteration() {
TypeScriptCompileTest.compileTest();
}
}
199 changes: 199 additions & 0 deletions TypeScript/build/import-src-project.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import fs from "fs";
import path from "path";
import { spawnSync } from "child_process";
import { globSync } from "glob";
import assert from 'assert/strict';
import { fileURLToPath } from "url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));


class Importer {
constructor({ projectName, size, repoUrl, srcFolder, extraFiles, extraDirs }) {
this.projectName = projectName;
assert(projectName.endsWith(`-${size}`), "missing size annotation in projectName");
this.repoUrl = repoUrl;
this.baseDir = path.resolve(__dirname);
let repoName = path.basename(this.repoUrl);
if (!repoName.endsWith(".git")) {
repoName = `${repoName}.git`;
}
this.repoDir = path.resolve(__dirname, repoName);
this.srcFolder = srcFolder;
this.outputDir = path.resolve(__dirname, `../src/gen/${this.projectName}`);
fs.mkdirSync(this.outputDir, { recursive: true });
this.srcFileData = Object.create(null);
this.extraFiles = extraFiles;
this.extraDirs = extraDirs;
}
run() {
this.cloneRepo();
this.readSrcFileData();
this.addExtraFilesFromDirs();
this.addSpecificFiles();
this.writeTsConfig();
this.writeSrcFileData();
}

cloneRepo() {
if (fs.existsSync(this.repoDir)) return;
console.info(`Cloning src data repository to ${this.repoDir}`);
spawnSync("git", ["clone", this.repoUrl, this.repoDir]);
}

readSrcFileData() {
const patterns = [`${this.srcFolder}/**/*.ts`, `${this.srcFolder}/**/*.d.ts`, `${this.srcFolder}/*.d.ts`];
patterns.forEach(pattern => {
const files = globSync(pattern, { cwd: this.repoDir, nodir: true });
files.forEach(file => {
const filePath = path.join(this.repoDir, file);
const relativePath = path.relative(this.repoDir, filePath).toLowerCase();
const fileContents = fs.readFileSync(filePath, "utf8");
this.addFileContents(relativePath, fileContents);
});
});
}

addExtraFilesFromDirs() {
this.extraDirs.forEach(({ dir, nameOnly = false }) => {
const absoluteSourceDir = path.resolve(__dirname, dir);
let allFiles = globSync("**/*.d.ts", { cwd: absoluteSourceDir, nodir: true });
allFiles = allFiles.concat(globSync("**/*.d.mts", { cwd: absoluteSourceDir, nodir: true }));

allFiles.forEach(file => {
const filePath = path.join(absoluteSourceDir, file);
let relativePath = path.join(dir, path.relative(absoluteSourceDir, filePath));
if (nameOnly) {
relativePath = path.basename(relativePath);
}
this.addFileContents(relativePath, fs.readFileSync(filePath, "utf8"))
});
});
}

addFileContents(relativePath, fileContents) {
if (relativePath in this.srcFileData) {
if (this.srcFileData[relativePath] !== fileContents) {
throw new Error(`${relativePath} was previously added with different contents.`);
}
} else {
this.srcFileData[relativePath] = fileContents;
}
}

addSpecificFiles() {
this.extraFiles.forEach(file => {
const filePath = path.join(this.baseDir, file);
this.srcFileData[file] = fs.readFileSync(filePath, "utf8");
});
}

writeSrcFileData() {
const filesDataPath = path.join(this.outputDir, "src_file_data.cjs");
fs.writeFileSync(
filesDataPath, `// Generated src file data from existing node modules and
// ${this.repoUrl}
// See LICENSEs in the sources.
module.exports = ${JSON.stringify(this.srcFileData, null, 2)};
`
);
const stats = fs.statSync(filesDataPath);
const fileSizeInKiB = (stats.size / 1024) | 0;
console.info(`Exported ${this.projectName}`);
console.info(` File Contents: ${path.relative(process.cwd(), filesDataPath)}`);
console.info(` Total Size: ${fileSizeInKiB} KiB`);
}

writeTsConfig() {
const tsconfigInputPath = path.join(this.repoDir, "tsconfig.json");
const mergedTsconfig = this.loadAndMergeTsconfig(tsconfigInputPath);
const tsconfigOutputPath = path.join(this.outputDir, "src_tsconfig.cjs");
fs.writeFileSync(
tsconfigOutputPath, `// Exported from ${this.repoUrl}
// See LICENSEs in the sources.
module.exports = ${JSON.stringify(mergedTsconfig, null, 2)};
`
);
}

loadAndMergeTsconfig(configPath) {
const tsconfigContent = fs.readFileSync(configPath, "utf8");
const tsconfigContentWithoutComments = tsconfigContent.replace(/(?:^|\s)\/\/.*$|\/\*[\s\S]*?\*\//gm, "");
const tsconfig = JSON.parse(tsconfigContentWithoutComments);
let baseConfigPath = tsconfig.extends;
if (!baseConfigPath) return tsconfig;
if (!baseConfigPath.startsWith('./') && !baseConfigPath.startsWith('../')) return tsconfig;

baseConfigPath = path.resolve(path.dirname(configPath), baseConfigPath);
const baseConfig = this.loadAndMergeTsconfig(baseConfigPath);

const mergedConfig = { ...baseConfig, ...tsconfig };
if (baseConfig.compilerOptions && tsconfig.compilerOptions) {
mergedConfig.compilerOptions = { ...baseConfig.compilerOptions, ...tsconfig.compilerOptions };
}
delete mergedConfig.extends;
return mergedConfig;
}
}

new Importer({
projectName: "jestjs-large",
size: "large",
repoUrl: "https://github.com/jestjs/jest.git",
srcFolder: "packages",
extraFiles: [
"../../node_modules/@babel/types/lib/index.d.ts",
"../../node_modules/callsites/index.d.ts",
"../../node_modules/camelcase/index.d.ts",
"../../node_modules/chalk/types/index.d.ts",
"../../node_modules/execa/index.d.ts",
"../../node_modules/fast-json-stable-stringify/index.d.ts",
"../../node_modules/get-stream/index.d.ts",
"../../node_modules/strip-json-comments/index.d.ts",
"../../node_modules/tempy/index.d.ts",
"../../node_modules/tempy/node_modules/type-fest/index.d.ts",
"../node_modules/@jridgewell/trace-mapping/types/trace-mapping.d.mts",
"../node_modules/@types/eslint/index.d.ts",
"../node_modules/ansi-regex/index.d.ts",
"../node_modules/ansi-styles/index.d.ts",
"../node_modules/glob/dist/esm/index.d.ts",
"../node_modules/jest-worker/build/index.d.ts",
"../node_modules/lru-cache/dist/esm/index.d.ts",
"../node_modules/minipass/dist/esm/index.d.ts",
"../node_modules/p-limit/index.d.ts",
"../node_modules/path-scurry/dist/esm/index.d.ts",
"../node_modules/typescript/lib/lib.dom.d.ts",
],
extraDirs: [
{ dir: "../node_modules/@types/" },
{ dir: "../node_modules/typescript/lib/", nameOnly: true },
{ dir: "../node_modules/jest-worker/build/" },
{ dir: "../node_modules/@jridgewell/trace-mapping/types/" },
{ dir: "../node_modules/minimatch/dist/esm/" },
{ dir: "../node_modules/glob/dist/esm/" },
{ dir: "../../node_modules/tempy/node_modules/type-fest/source/" }
],
}).run();

new Importer({
projectName: "zod-medium",
size: "medium",
repoUrl: "https://github.com/colinhacks/zod.git",
srcFolder: "packages",
extraFiles: [],
extraDirs: [
{ dir: "../node_modules/typescript/lib/", nameOnly: true },
],
}).run();

// Import tiny-sized project sources:
new Importer({
projectName: "immer-tiny",
size: "tiny",
repoUrl: "https://github.com/immerjs/immer.git",
srcFolder: "src",
extraFiles: [],
extraDirs: [
{ dir: "../node_modules/typescript/lib/", nameOnly: true },
],
}).run();
11 changes: 11 additions & 0 deletions TypeScript/build/postbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require("fs");
const path = require("path");

console.log("Creating importable source string")
const bundlePath = path.join(__dirname, "..", "dist", "typescript-compile-test.js");
const srcOutPath = path.join(__dirname, "..", "dist", "typescript-compile-test.src.js");

const bundleContent = fs.readFileSync(bundlePath, "utf8");
const srcContent = `REACT_RENDER_TEST_SRC = ${JSON.stringify(bundleContent)};`;
fs.writeFileSync(srcOutPath, srcContent);
console.log(`Successfully created ${srcOutPath}`);
7 changes: 7 additions & 0 deletions TypeScript/dist/typescript-compile-test.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions TypeScript/dist/typescript-compile-test.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions TypeScript/dist/typescript-compile-test.src.js

Large diffs are not rendered by default.

Loading
Loading