Skip to content

Commit

Permalink
Merge branch 'main' into ewitkon/expoTemplate
Browse files Browse the repository at this point in the history
merge main
  • Loading branch information
ewitkon committed Dec 5, 2024
2 parents 7cb9ff8 + 1b60b3d commit 7813ae6
Show file tree
Hide file tree
Showing 30 changed files with 1,541 additions and 1,740 deletions.
9 changes: 9 additions & 0 deletions .changeset/dry-foxes-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@osdk/foundry-sdk-generator": patch
"@osdk/cli.cmd.typescript": patch
"@osdk/shared.client.impl": patch
"@osdk/shared.net": patch
"@osdk/cli": patch
---

Packages use more specific versions instead of indirection through shared.net
5 changes: 5 additions & 0 deletions .changeset/lovely-news-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/react": patch
---

Adjusts dependencies on @osdk/client and @osdk/api to work with prerelease packages
5 changes: 5 additions & 0 deletions .changeset/shiny-suns-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/create-app.template.react.beta": patch
---

"Fixes dependency on OSDK"
2 changes: 2 additions & 0 deletions .monorepolint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ 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.*",
];

// Packages that should have the `check-api` task installed
Expand All @@ -72,6 +73,7 @@ const privatePackages = [
"@osdk/tests.verify-fallback-package-v2",
"@osdk/tool.*",
"@osdk/version-updater",
"@osdk/benchmarks.*",
];

const consumerCliPackages = [
Expand Down
131 changes: 131 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
Currently, we only have one benchmark.

```
cd tests/primary
pnpm exec turbo bundle
pnpm run benchmark
cat build/benchmark/results.json
```

example output:

```
{
"tests": {
"import.createClient.esbuild.js": {
"runs": [
{
"type": "result",
"time": 14.41,
"heapUsed": 1362704,
"rss": 1884160
},
...,
{
"type": "result",
"time": 14.66,
"heapUsed": 1362680,
"rss": 2392064
}
],
"stats": {
"time": {
"std": 0.6165480967090525,
"mean": 14.905333333333335,
"min": 14.41,
"max": 16.7
},
"heapUsed": {
"std": 41.845429857990474,
"mean": 1362665.6,
"min": 1362632,
"max": 1362752
},
"rss": {
"std": 243298.56906823127,
"mean": 2170333.8666666667,
"min": 1818624,
"max": 2506752
}
}
},
"import.createClient.js": {
"runs": [
{
"type": "result",
"time": 36.3,
"heapUsed": 2090960,
"rss": 5619712
},
...,
{
"type": "result",
"time": 38.81,
"heapUsed": 2094352,
"rss": 5996544
}
],
"stats": {
"time": {
"std": 1.561981078274923,
"mean": 38.35466666666668,
"min": 36.3,
"max": 41.92
},
"heapUsed": {
"std": 1157.6154494860928,
"mean": 2092049.0666666667,
"min": 2090744,
"max": 2094352
},
"rss": {
"std": 326074.07364803203,
"mean": 5936469.333333333,
"min": 5505024,
"max": 6602752
}
}
},
"noop.js": {
"runs": [
{
"type": "result",
"time": 0.01,
"heapUsed": 1368,
"rss": 81920
},
...,
{
"type": "result",
"time": 0.01,
"heapUsed": 1368,
"rss": 49152
}
],
"stats": {
"time": {
"std": 0.012220201853215573,
"mean": 0.018000000000000002,
"min": 0.01,
"max": 0.06
},
"heapUsed": {
"std": 0,
"mean": 1368,
"min": 1368,
"max": 1368
},
"rss": {
"std": 50410.207135724675,
"mean": 32768,
"min": 0,
"max": 180224
}
}
}
},
"sizes": {
"esbuild/bundle.js": 128543
}
}
```
32 changes: 32 additions & 0 deletions benchmarks/tests/primary/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "@osdk/benchmarks.primary",
"private": true,
"version": "0.0.0",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/palantir/osdk-ts.git"
},
"scripts": {
"benchmark": "node --allow-natives-syntax src/benchmark.js",
"bundle:esbuild": "esbuild src/bundle.js --bundle --platform=node --target=node18 --format=esm --outfile=build/esbuild/bundle.js --external:isomorphic-ws --external:fetch-retry"
},
"dependencies": {
"@osdk/client": "workspace:*"
},
"peerDependencies": {
"fetch-retry": "*",
"isomorphic-ws": "*"
},
"devDependencies": {
"@types/node": "^22",
"cli-progress": "^3.12.0",
"esbuild": "^0.24.0",
"execa": "^9.5.1",
"express": "^4.21.1",
"fast-deep-equal": "3.1.3",
"mathjs": "^14.0.0",
"tiny-invariant": "^1.3.3"
},
"type": "module"
}
175 changes: 175 additions & 0 deletions benchmarks/tests/primary/src/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* 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.
*/

// @ts-check

import cliProgress from "cli-progress";
import { execaNode } from "execa";
import { mean, std } from "mathjs";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import invariant from "tiny-invariant";
import { fixDirname } from "./helpers.js";

fixDirname(import.meta);

const WARMUP_ITERATIONS = 1;
const ITERATIONS = 10;

async function main() {
const multiBar = new cliProgress.MultiBar(
{
format: "[{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | {name}",
clearOnComplete: true,
},
cliProgress.Presets.shades_classic,
);

const tests = [
"createObjects.js",
"import.createClient.esbuild.js",
"import.createClient.js",
"noop.js",
];

const overallBar = multiBar.create(
tests.length * (WARMUP_ITERATIONS + ITERATIONS),
0,
{ name: "Overall" },
);

const final = {
tests: {},
sizes: {},
};

for (const test of tests) {
const progressBar = multiBar.create(WARMUP_ITERATIONS + ITERATIONS, 0, {
name: test,
});
for (let i = 0; i < WARMUP_ITERATIONS; i++) {
await runTest(test);
progressBar.increment();
overallBar.increment();
}

const results = [];
for (let i = 0; i < ITERATIONS; i++) {
const result = await runTest(test);
results.push(result);
progressBar.increment();
overallBar.increment();
}

const combinedResults = Object.fromEntries(
["time", "heapUsed", "rss"].map((key) => [
key,
{
std: std(results.map((x) => x[key]), "uncorrected"),
mean: mean(results.map((x) => x[key])),
min: Math.min(...results.map((x) => x[key])),
max: Math.max(...results.map((x) => x[key])),
},
]),
);

final.tests[test] = {
runs: results,
stats: combinedResults,
};
}
multiBar.stop();

const esBuildStats = await fs.stat(
path.join(import.meta.dirname, "..", "build", "esbuild", "bundle.js"),
);
final.sizes["esbuild/bundle.js"] = esBuildStats.size;

const outDir = path.join(import.meta.dirname, "..", "build", "benchmark");
await fs.mkdir(outDir, { recursive: true });
await fs.writeFile(
path.join(outDir, "results.json"),
JSON.stringify(final, null, 2),
);
}

/**
* @param {string} test
* @returns {Promise<import("./types.js").Result>}
*/
async function runTest(test) {
const closeSidecar = await createSidecar(test);

try {
const subprocess = execaNode({
nodeOptions: [
"--allow-natives-syntax",
"--expose-gc",
// "--max-old-space-size=10",
],
ipc: true,
})`${path.join(import.meta.dirname, "tests", test)}`;
try {
await subprocess.sendMessage({ "type": "start" });

/** @type {import("./types.js").Result} */
const response = /** @type any */ (await subprocess.getOneMessage());
invariant(
response.type === "result" && "time" in response
&& "heapUsed" in response
&& "rss" in response,
);
return response;
} catch (e) {
console.log(e);
console.log((await subprocess).code);
// console.log(subprocess.stdout);
// console.log(subprocess.stderr);
throw e;
}
} finally {
if (closeSidecar) {
await closeSidecar();
}
}
}

main();

async function createSidecar(test) {
const sidecarPath = path.join(import.meta.dirname, "sidecars", test);

const createSidecar = await fileExists(sidecarPath)
? (await import(sidecarPath)).default
: undefined;

/** @type {undefined | (() => Promise<void>)} */
const closeSidecar = createSidecar ? await createSidecar() : undefined;
return closeSidecar;
}

async function fileExists(filePath) {
try {
await fs.access(filePath);
return true;
} catch (err) {
if (err.code === "ENOENT") {
return false;
} else {
throw err; // Rethrow other errors
}
}
}
19 changes: 19 additions & 0 deletions benchmarks/tests/primary/src/bundle.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 { createClient } from "@osdk/client";

export { createClient };
Loading

0 comments on commit 7813ae6

Please sign in to comment.