Skip to content

Commit a97aa71

Browse files
committed
remove parallelism to debug performance
1 parent f621054 commit a97aa71

File tree

5 files changed

+95
-70
lines changed

5 files changed

+95
-70
lines changed

src/generators/jsx-ast/index.mjs

Lines changed: 48 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
import { OVERRIDDEN_POSITIONS } from './constants.mjs';
2+
import { buildSideBarProps } from './utils/buildBarProps.mjs';
23
import buildContent from './utils/buildContent.mjs';
3-
import {
4-
getCompatibleVersions,
5-
getVersionFromSemVer,
6-
getVersionURL,
7-
groupNodesByModule,
8-
} from '../../utils/generators.mjs';
4+
import { groupNodesByModule } from '../../utils/generators.mjs';
95
import { getRemarkRecma } from '../../utils/remark.mjs';
106

117
/**
12-
* This generator generates a JSX AST from an input MDAST
8+
* Generator for converting MDAST to JSX AST.
139
*
1410
* @typedef {Array<ApiDocMetadataEntry>} Input
15-
*
1611
* @type {GeneratorMetadata<Input, string>}
1712
*/
18-
export default {
13+
14+
/**
15+
* Sorts entries by OVERRIDDEN_POSITIONS and then heading name.
16+
* @param {Array<ApiDocMetadataEntry>} entries
17+
*/
18+
const getSortedHeadNodes = entries => {
19+
return entries
20+
.filter(node => node.heading.depth === 1)
21+
.sort((a, b) => {
22+
const ai = OVERRIDDEN_POSITIONS.indexOf(a.api);
23+
const bi = OVERRIDDEN_POSITIONS.indexOf(b.api);
24+
25+
if (ai !== -1 && bi !== -1) {
26+
return ai - bi;
27+
}
28+
29+
if (ai !== -1) {
30+
return -1;
31+
}
32+
33+
if (bi !== -1) {
34+
return 1;
35+
}
36+
37+
return a.heading.data.name.localeCompare(b.heading.data.name);
38+
});
39+
};
40+
41+
const jsxAstGenerator = {
1942
name: 'jsx-ast',
2043
version: '1.0.0',
2144
description: 'Generates JSX AST from the input MDAST',
@@ -31,70 +54,35 @@ export default {
3154
async generate(entries, { index, releases, version }) {
3255
const remarkRecma = getRemarkRecma();
3356
const groupedModules = groupNodesByModule(entries);
34-
35-
// Get sorted primary heading nodes
36-
const headNodes = entries
37-
.filter(node => node.heading.depth === 1)
38-
.sort((a, b) => {
39-
const ai = OVERRIDDEN_POSITIONS.indexOf(a.api),
40-
bi = OVERRIDDEN_POSITIONS.indexOf(b.api);
41-
// If this is in OVERRIDDEN_POSITIONS, it must come first
42-
return ai !== -1 && bi !== -1
43-
? ai - bi
44-
: ai !== -1
45-
? -1
46-
: bi !== -1
47-
? 1
48-
: // Just compare headings
49-
a.heading.data.name.localeCompare(b.heading.data.name);
50-
});
57+
const headNodes = getSortedHeadNodes(entries);
5158

5259
// Generate table of contents
5360
const docPages = index
5461
? index.map(({ section, api }) => [section, `${api}.html`])
5562
: headNodes.map(node => [node.heading.data.name, `${node.api}.html`]);
5663

5764
// Process each head node and build content
58-
const results = await Promise.all(
59-
headNodes.map(entry => {
60-
const versions = getCompatibleVersions(
61-
entry.introduced_in,
62-
releases,
63-
true
64-
);
65-
66-
const sideBarProps = {
67-
versions: versions.map(({ version, isLts, isCurrent }) => {
68-
const parsed = getVersionFromSemVer(version);
69-
let label = `v${parsed}`;
65+
const results = [];
66+
for (const entry of headNodes) {
67+
const sideBarProps = buildSideBarProps(
68+
entry,
69+
releases,
70+
version,
71+
docPages
72+
);
7073

71-
if (isLts) {
72-
label += ' (LTS)';
73-
}
74-
75-
if (isCurrent) {
76-
label += ' (Current)';
77-
}
78-
79-
return {
80-
value: getVersionURL(parsed, entry.api),
81-
label,
82-
};
83-
}),
84-
currentVersion: `v${version.version}`,
85-
pathname: `${entry.api}.html`,
86-
docPages,
87-
};
88-
89-
return buildContent(
74+
results.push(
75+
await buildContent(
9076
groupedModules.get(entry.api),
9177
entry,
9278
sideBarProps,
9379
remarkRecma
94-
);
95-
})
96-
);
80+
)
81+
);
82+
}
9783

9884
return results;
9985
},
10086
};
87+
88+
export default jsxAstGenerator;

src/generators/jsx-ast/utils/buildBarProps.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import readingTime from 'reading-time';
22
import { visit } from 'unist-util-visit';
33

44
import { DOC_API_BLOB_EDIT_BASE_URL } from '../../../constants.mjs';
5+
import {
6+
getCompatibleVersions,
7+
getVersionFromSemVer,
8+
getVersionURL,
9+
} from '../../../utils/generators.mjs';
510

611
/**
712
* Builds metadata for the sidebar and meta bar
@@ -42,3 +47,36 @@ export const buildMetaBarProps = (head, entries) => {
4247
editThisPage: `${DOC_API_BLOB_EDIT_BASE_URL}${head.api}.md`,
4348
};
4449
};
50+
51+
/**
52+
* Builds the sidebar properties for a given entry.
53+
* @param {ApiDocMetadataEntry} entry
54+
* @param {Array<ApiDocReleaseEntry>} releases
55+
* @param {import('semver').SemVer} version
56+
* @param {Array<[string, string]>} docPages
57+
*/
58+
export const buildSideBarProps = (entry, releases, version, docPages) => {
59+
const versions = getCompatibleVersions(entry.introduced_in, releases, true);
60+
61+
return {
62+
versions: versions.map(({ version, isLts, isCurrent }) => {
63+
const parsed = getVersionFromSemVer(version);
64+
65+
let label = `v${parsed}`;
66+
if (isLts) {
67+
label += ' (LTS)';
68+
}
69+
if (isCurrent) {
70+
label += ' (Current)';
71+
}
72+
73+
return {
74+
value: getVersionURL(parsed, entry.api),
75+
label,
76+
};
77+
}),
78+
currentVersion: `v${version.version}`,
79+
pathname: `${entry.api}.html`,
80+
docPages,
81+
};
82+
};

src/generators/jsx-ast/utils/buildContent.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,16 @@ const createDocumentLayout = (entries, sideBarProps, metaBarProps) => {
224224
* @param {import('unified').Processor} remark - Remark processor instance for markdown processing
225225
* @returns {JSXContent} The processed MDX content
226226
*/
227-
const buildContent = (metadataEntries, head, sideBarProps, remark) => {
227+
const buildContent = async (metadataEntries, head, sideBarProps, remark) => {
228228
const metaBarProps = buildMetaBarProps(head, metadataEntries);
229229

230230
const root = createDocumentLayout(
231231
metadataEntries,
232232
sideBarProps,
233233
metaBarProps
234234
);
235-
const ast = remark.runSync(root);
235+
236+
const ast = await remark.run(root);
236237

237238
// ast => { Program: { Expression: { JSX } } }
238239
return {

src/generators/web/index.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ export default {
107107
const require = createRequire(RESOLVE_DIR);
108108

109109
// Process all entries
110-
// TODO(@avivkeller): Remove parallelism, as it can cause memory crashes
111-
const results = await Promise.all(
112-
entries.map(entry =>
113-
processEntry(entry, template, astBuilders, require, output)
114-
)
115-
);
110+
const results = [];
111+
for (const entry of entries) {
112+
results.push(
113+
await processEntry(entry, template, astBuilders, require, output)
114+
);
115+
}
116116

117117
if (output) {
118118
await writeFile(

src/generators/web/ui/components/ChangeHistory.jsx

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)