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

Second round of the benchmarks #1036

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
3 changes: 2 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"@osdk/version-updater",
"@osdk/e2e.test.foundry-sdk-generator",
"@osdk/e2e.generated.*",
"@osdk/e2e.sandbox.*"
"@osdk/e2e.sandbox.*",
"@osdk/benchmarks.*"
],
"bumpVersionsWithWorkspaceProtocolOnly": true,
"snapshot": {
Expand Down
2 changes: 2 additions & 0 deletions .changeset/selfish-pans-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
43 changes: 41 additions & 2 deletions .monorepolint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ const nonStandardPackages = [
"@osdk/widget-manifest-vite-plugin", // has a vite-bundled app + react
// removed the following from the repo to avoid it being edited
// "@osdk/shared.client2", // hand written package that only exposes a symbol
"@osdk/benchmarks.*",
"@osdk/benchmarks.tests.*",
"@osdk/benchmarks.bundles.*",
"@osdk/benchmarks.lib.v8",
"@osdk/benchmarks.memtests.*",
];

// Packages that should have the `check-api` task installed
Expand Down Expand Up @@ -673,9 +676,9 @@ NOTE: DO NOT EDIT THIS README BY HAND. It is generated by monorepolint.
...rulesForPackagesWithChecKApiTask(),

packageEntry({
excludePackages: ["@osdk/benchmarks.*"],
options: {
entries: {
license: "Apache-2.0",
repository: {
"type": "git",
"url": "https://github.com/palantir/osdk-ts.git",
Expand All @@ -685,6 +688,15 @@ NOTE: DO NOT EDIT THIS README BY HAND. It is generated by monorepolint.
},
}),

packageEntry({
options: {
entries: {
license: "Apache-2.0",
},
entriesExist: ["version"],
},
}),

requireDependency({
includePackages: [
"@osdk/foundry.*",
Expand All @@ -700,6 +712,33 @@ NOTE: DO NOT EDIT THIS README BY HAND. It is generated by monorepolint.
},
}),

packageEntry({
includePackages: ["@osdk/benchmarks.memtests.*"],
options: {
entries: {
type: "module",
},
},
}),

packageScript({
includePackages: ["@osdk/benchmarks.memtests.*"],
options: {
scripts: {
"benchmark-serial": "benchmarks.lib.test mem-test",
},
},
}),

requireDependency({
includePackages: ["@osdk/benchmarks.memtests.*"],
options: {
dependencies: {
"@osdk/benchmarks.lib.test": "workspace:*",
},
},
}),

packageEntry({
options: {
entries: {
Expand Down
26 changes: 26 additions & 0 deletions benchmarks/bundles/simple/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@osdk/benchmarks.bundles.simple",
"private": true,
"version": "0.0.0",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/palantir/osdk-ts.git"
},
"scripts": {
"benchmark-parallel": "benchmarks.lib.bundler-esbuild"
},
"dependencies": {
"@osdk/client": "workspace:*",
"@osdk/oauth": "workspace:*"
},
"peerDependencies": {
"fetch-retry": "*",
"isomorphic-ws": "*"
},
"devDependencies": {
"@osdk/benchmarks.lib.bundler-esbuild": "workspace:*",
"esbuild": "^0.24.0"
},
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
* limitations under the License.
*/

export interface Result {
type: "result";
time: number;
heapUsed: number;
rss: number;
}
import { createPublicOauthClient } from "@osdk/oauth";

export { createPublicOauthClient };
Copy link
Contributor

@nihalbhatnagar nihalbhatnagar Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?(here and client)

19 changes: 19 additions & 0 deletions benchmarks/libraries/bundler-esbuild/bin/bundler-esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { build } from "../build/esm/index.js";

await build(process.cwd());
65 changes: 65 additions & 0 deletions benchmarks/libraries/bundler-esbuild/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "@osdk/benchmarks.lib.bundler-esbuild",
"private": true,
"version": "0.0.0",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/palantir/osdk-ts.git"
},
"exports": {
".": {
"browser": "./build/browser/index.js",
"import": "./build/esm/index.js",
"default": "./build/browser/index.js"
},
"./*": {
"browser": "./build/browser/public/*.js",
"import": "./build/esm/public/*.js",
"default": "./build/browser/public/*.js"
}
},
"scripts": {
"check-attw": "monorepo.tool.attw esm",
"check-spelling": "cspell --quiet .",
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
"transpile": "monorepo.tool.transpile"
},
"dependencies": {
"@osdk/client": "workspace:*"
},
"peerDependencies": {
"fetch-retry": "*",
"isomorphic-ws": "*"
},
"devDependencies": {
"@osdk/monorepo.api-extractor": "workspace:~",
"@osdk/monorepo.tsconfig": "workspace:~",
"@osdk/monorepo.tsup": "workspace:~",
"@types/node": "^22",
"esbuild": "^0.24.0",
"execa": "^9.5.1",
"fast-deep-equal": "3.1.3",
"mathjs": "^14.0.0",
"tiny-invariant": "^1.3.3",
"typescript": "~5.5.4"
},
"publishConfig": {
"access": "public"
},
"bin": "./bin/bundler-esbuild.js",
"files": [
"build/cjs",
"build/esm",
"build/browser",
"CHANGELOG.md",
"package.json",
"templates",
"*.d.ts"
],
"module": "./build/esm/index.js",
"types": "./build/esm/index.d.ts",
"type": "module"
}
100 changes: 100 additions & 0 deletions benchmarks/libraries/bundler-esbuild/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as esbuild from "esbuild";
import * as fs from "node:fs/promises";
import * as path from "node:path";

export async function build(dirPath: string) {
const dir = await fs.opendir(path.join(dirPath, "src"));

const entryPoints: string[] = [];

for await (const dirent of dir) {
if (
dirent.isFile() && (
dirent.name.endsWith(".ts")
|| dirent.name.endsWith(".js")
)
) {
entryPoints.push(dirent.name);
}
}

const baseOutDir = path.join(
dirPath,
"build",
"benchmark",
"bundler",
"esbuild",
);
const results: esbuild.BuildResult[] = [];
for (const entryPoint of entryPoints) {
const baseName = path.basename(entryPoint, path.extname(entryPoint));
for (const minify of [true, false]) {
for (const platform of ["node", "browser"]) {
const result = await esbuild.build({
entryPoints: [`src/${entryPoint}`],
bundle: true,
minify,

external: ["isomorphic-ws", "fetch-retry"],
format: "esm",
...(platform === "node"
? { platform: "node", target: "node18" }
: {
platform: "browser",
}),
outfile: path.join(
baseOutDir,
`${baseName}.${platform}${minify ? ".min" : ""}.js`,
),
});
results.push(result);
}
}
}

const r = await collectStats(baseOutDir, {}, baseOutDir);
await fs.writeFile(
path.join(baseOutDir, "stats.json"),
JSON.stringify(r, null, 2),
);
}

async function collectStats(
dirPath: string,
results: Record<string, number>,
relPath: string,
) {
const dir = await fs.opendir(dirPath);

for await (const filePath of dir) {
if (filePath.isFile() && filePath.name.endsWith(".js")) {
const stats = await fs.stat(path.join(dirPath, filePath.name));
results[path.relative(relPath, path.join(dirPath, filePath.name))] =
stats.size;
} else if (filePath.isDirectory()) {
await collectStats(
path.join(dirPath, filePath.name),
results,
relPath,
);
}
}

return results;
}
11 changes: 11 additions & 0 deletions benchmarks/libraries/bundler-esbuild/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@osdk/monorepo.tsconfig/base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build/esm"
},
"include": [
"./src/**/*"
],
"references": []
}
23 changes: 23 additions & 0 deletions benchmarks/libraries/bundler-esbuild/tsup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { defineConfig } from "tsup";

export default defineConfig(async (options) =>
(await import("@osdk/monorepo.tsup")).default(options, {
esmOnly: true,
})
);
24 changes: 24 additions & 0 deletions benchmarks/libraries/bundler-esbuild/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { configDefaults, defineConfig } from "vitest/config";

export default defineConfig({
test: {
pool: "forks",
exclude: [...configDefaults.exclude, "**/build/**/*"],
},
});
19 changes: 19 additions & 0 deletions benchmarks/libraries/test/bin/benchmarks.lib.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { cli } from "../build/esm/cli/cli.js";

await cli();
Loading
Loading