这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/itchy-items-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix(parser): cache visited graph nodes to boost performance
26 changes: 26 additions & 0 deletions debug-helpers/graph-hotspots.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

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

// Load your exported graph
const nodes = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'graph.json'), 'utf-8'),
);

// Annotate nodes with children count
const annotatedNodes = nodes.map((n) => ({
childrenCount: n.childrenPointers?.length ?? 0,
pointer: n.pointer,
}));

// Sort by childrenCount descending
annotatedNodes.sort((a, b) => b.childrenCount - a.childrenCount);

// Print top 20 hotspots
console.log('Top 20 potential bottleneck nodes:\n');
annotatedNodes.slice(0, 20).forEach((n) => {
console.log(`${n.pointer} — children: ${n.childrenCount}`);
});
60 changes: 60 additions & 0 deletions debug-helpers/json-to-dot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

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

const nodes = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'graph.json'), 'utf-8'),
);

// --- Filter nodes for readability ---
const threshold = 10; // high-fanout threshold
const filteredSet = new Set();

// Include nodes with children > threshold and their immediate children
for (const n of nodes) {
const childCount = n.childrenPointers?.length ?? 0;
if (childCount > threshold) {
filteredSet.add(n.pointer);
for (const child of n.childrenPointers || []) {
filteredSet.add(child);
}
}
}

// Filtered nodes list
const filteredNodes = nodes.filter((n) => filteredSet.has(n.pointer));

// Start the .dot file
let dot = 'digraph OpenAPIGraph {\nrankdir=LR;\nnode [style=filled];\n';

// Add nodes with color based on fanout
for (const n of filteredNodes) {
const childCount = n.childrenPointers?.length ?? 0;
const color =
childCount > 50 ? 'red' : childCount > 20 ? 'orange' : 'lightgray';
dot += `"${n.pointer}" [label="${n.pointer}\\n${childCount} children", fillcolor=${color}];\n`;
}

// Add edges: node -> its children
for (const n of filteredNodes) {
for (const child of n.childrenPointers || []) {
if (filteredSet.has(child)) {
dot += `"${n.pointer}" -> "${child}";\n`;
}
}
}

dot += '}\n';

// Write to a file
fs.writeFileSync(path.resolve(__dirname, 'graph.dot'), dot);
console.log('graph.dot created!');

// Instructions:
// Render with Graphviz:
// dot -Tpng graph.dot -o graph.png
// or
// dot -Tsvg graph.dot -o graph.svg
8 changes: 4 additions & 4 deletions packages/openapi-ts-tests/main/test/openapi-ts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export default defineConfig(() => {
// },
path: path.resolve(
getSpecsPath(),
'3.0.x',
'3.1.x',
// 'invalid',
'perf.yaml',
'full.yaml',
// 'validators-circular-ref.json',
),
// path: 'http://localhost:4000/',
Expand All @@ -54,7 +54,7 @@ export default defineConfig(() => {
// },
},
logs: {
level: 'debug',
// level: 'debug',
path: './logs',
},
// name: 'foo',
Expand Down Expand Up @@ -107,7 +107,7 @@ export default defineConfig(() => {
// name: '{{name}}',
},
readWrite: {
enabled: false,
// enabled: false,
requests: '{{name}}Writable',
responses: '{{name}}',
},
Expand Down
Loading
Loading