Skip to content

Commit

Permalink
Some performance work, go faster!
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Jun 25, 2023
1 parent c1c87c6 commit d4098e8
Show file tree
Hide file tree
Showing 17 changed files with 494 additions and 455 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -15,10 +15,12 @@ yarn-error.log
/coverage/
/dist/
/docs
/docs2
/td*.json

typedoc*.tgz
tmp
/*.0x/

src/test/renderer/specs/assets/*
src/test/renderer/specs/specs.json
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
# Unreleased

### Features

- Implemented several miscellaneous performance improvements to generate docs faster, this took the time to generate TypeDoc's
site from ~5.6 seconds to ~5.4 seconds.

## v0.24.8 (2023-06-04)

### Features
Expand Down
767 changes: 382 additions & 385 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Expand Up @@ -26,8 +26,8 @@
"dependencies": {
"lunr": "^2.3.9",
"marked": "^4.3.0",
"minimatch": "^9.0.0",
"shiki": "^0.14.1"
"minimatch": "^9.0.2",
"shiki": "^0.14.2"
},
"peerDependencies": {
"typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x"
Expand All @@ -37,14 +37,14 @@
"@types/marked": "^4.0.8",
"@types/mocha": "^10.0.1",
"@types/node": "14",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"@typestrong/fs-fixture-builder": "github:TypeStrong/fs-fixture-builder#8abd1494280116ff5318dde2c50ad01e1663790c",
"c8": "^7.13.0",
"esbuild": "^0.17.16",
"eslint": "^8.38.0",
"c8": "^8.0.0",
"esbuild": "^0.18.8",
"eslint": "^8.43.0",
"mocha": "^10.2.0",
"prettier": "2.8.7",
"prettier": "2.8.8",
"puppeteer": "^13.5.2",
"ts-node": "^10.9.1",
"typescript": "5.1.3"
Expand Down
12 changes: 8 additions & 4 deletions src/lib/converter/converter.ts
Expand Up @@ -419,7 +419,7 @@ export class Converter extends ChildableComponent<
for (const exp of allExports.filter((exp) =>
isDirectExport(context.resolveAliasedSymbol(exp), node)
)) {
convertSymbol(moduleContext, exp);
this.convertSymbol(moduleContext, exp);
}

return moduleContext;
Expand All @@ -434,7 +434,7 @@ export class Converter extends ChildableComponent<
(exp) =>
!isDirectExport(moduleContext.resolveAliasedSymbol(exp), node)
)) {
convertSymbol(moduleContext, exp);
this.convertSymbol(moduleContext, exp);
}
}

Expand All @@ -448,8 +448,12 @@ export class Converter extends ChildableComponent<
this.trigger(Converter.EVENT_RESOLVE_BEGIN, context);
const project = context.project;

for (const reflection of Object.values(project.reflections)) {
this.trigger(Converter.EVENT_RESOLVE, context, reflection);
for (const id in project.reflections) {
this.trigger(
Converter.EVENT_RESOLVE,
context,
project.reflections[id]
);
}

this.trigger(Converter.EVENT_RESOLVE_END, context);
Expand Down
7 changes: 4 additions & 3 deletions src/lib/converter/plugins/ImplementsPlugin.ts
Expand Up @@ -169,9 +169,10 @@ export class ImplementsPlugin extends ConverterComponent {
}

private resolve(project: ProjectReflection) {
for (const reflection of Object.values(project.reflections)) {
if (reflection instanceof DeclarationReflection) {
this.tryResolve(project, reflection);
for (const id in project.reflections) {
const refl = project.reflections[id];
if (refl instanceof DeclarationReflection) {
this.tryResolve(project, refl);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/converter/plugins/InheritDocPlugin.ts
Expand Up @@ -50,7 +50,8 @@ export class InheritDocPlugin extends ConverterComponent {
* that will provide actual comment.
*/
private processInheritDoc(project: ProjectReflection) {
for (const reflection of Object.values(project.reflections)) {
for (const id in project.reflections) {
const reflection = project.reflections[id];
const source = extractInheritDocTagReference(reflection);
if (!source) continue;

Expand Down
3 changes: 2 additions & 1 deletion src/lib/converter/plugins/LinkResolverPlugin.ts
Expand Up @@ -30,7 +30,8 @@ export class LinkResolverPlugin extends ConverterComponent {
}

resolveLinks(project: ProjectReflection) {
for (const reflection of Object.values(project.reflections)) {
for (const id in project.reflections) {
const reflection = project.reflections[id];
if (reflection.comment) {
this.owner.resolveLinks(reflection.comment, reflection);
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/converter/plugins/SourcePlugin.ts
Expand Up @@ -148,7 +148,9 @@ export class SourcePlugin extends ConverterComponent {
const basePath =
this.basePath || getCommonDirectory([...this.fileNames]);

for (const refl of Object.values(context.project.reflections)) {
for (const id in context.project.reflections) {
const refl = context.project.reflections[id];

if (
!(
refl instanceof DeclarationReflection ||
Expand Down
4 changes: 2 additions & 2 deletions src/lib/converter/plugins/TypePlugin.ts
Expand Up @@ -33,8 +33,8 @@ export class TypePlugin extends ConverterComponent {
}

private onRevive(project: ProjectReflection) {
for (const refl of Object.values(project.reflections)) {
this.resolve(project, refl);
for (const id in project.reflections) {
this.resolve(project, project.reflections[id]);
}
this.finishResolve(project);
this.reflections.clear();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/models/reflections/project.ts
Expand Up @@ -255,7 +255,8 @@ export class ProjectReflection extends ContainerReflection {
private getReferenceGraph(): Map<number, number[]> {
if (!this.referenceGraph) {
this.referenceGraph = new Map();
for (const ref of Object.values(this.reflections)) {
for (const id in this.reflections) {
const ref = this.reflections[id];
if (ref instanceof ReferenceReflection) {
const target = ref.tryGetTargetReflection();
if (target) {
Expand Down
11 changes: 2 additions & 9 deletions src/lib/output/components.ts
Expand Up @@ -59,14 +59,7 @@ export abstract class ContextAwareRendererComponent extends RendererComponent {
if (this.urlPrefix.test(absolute)) {
return absolute;
} else {
const relative = Path.relative(
Path.dirname(this.location),
Path.dirname(absolute)
);
return Path.join(relative, Path.basename(absolute)).replace(
/\\/g,
"/"
);
return Path.posix.relative(this.location, absolute) || ".";
}
}

Expand All @@ -85,7 +78,7 @@ export abstract class ContextAwareRendererComponent extends RendererComponent {
* @param page An event object describing the current render operation.
*/
protected onBeginPage(page: PageEvent<Reflection>) {
this.location = page.url;
this.location = Path.posix.dirname(page.url);
this.page = page;
}
}
2 changes: 1 addition & 1 deletion src/lib/output/renderer.ts
Expand Up @@ -26,6 +26,7 @@ import type { JsxElement } from "../utils/jsx.elements";
import type { DefaultThemeRenderContext } from "./themes/default/DefaultThemeRenderContext";
import { clearSeenIconCache } from "./themes/default/partials/icon";
import { validateStateIsClean } from "./themes/default/partials/type";
import { setRenderSettings } from "../utils/jsx";

/**
* Describes the hooks available to inject output in the default theme.
Expand Down Expand Up @@ -405,4 +406,3 @@ export class Renderer extends ChildableComponent<
// HACK: THIS HAS TO STAY DOWN HERE
// if you try to move it up to the top of the file, then you'll run into stuff being used before it has been defined.
import "./plugins";
import { setRenderSettings } from "../utils/jsx";
26 changes: 13 additions & 13 deletions src/lib/output/themes/default/partials/navigation.tsx
Expand Up @@ -107,10 +107,10 @@ export function settings(context: DefaultThemeRenderContext) {

type NavigationElement = ReflectionCategory | ReflectionGroup | DeclarationReflection;

function getNavigationElements(
const getNavigationElements = function getNavigationElements(
parent: NavigationElement | ProjectReflection,
opts: { includeCategories: boolean; includeGroups: boolean }
): NavigationElement[] {
): undefined | readonly NavigationElement[] {
if (parent instanceof ReflectionCategory) {
return parent.children;
}
Expand All @@ -123,7 +123,7 @@ function getNavigationElements(
}

if (!parent.kindOf(ReflectionKind.SomeModule | ReflectionKind.Project)) {
return [];
return;
}

if (parent.categories && opts.includeCategories) {
Expand All @@ -134,10 +134,10 @@ function getNavigationElements(
return parent.groups;
}

return parent.children || [];
}
return parent.children;
};

export function navigation(context: DefaultThemeRenderContext, props: PageEvent<Reflection>) {
export const navigation = function navigation(context: DefaultThemeRenderContext, props: PageEvent<Reflection>) {
const opts = context.options.getValue("navigation");
// Create the navigation for the current page
// Recurse to children if the parent is some kind of module
Expand All @@ -146,7 +146,7 @@ export function navigation(context: DefaultThemeRenderContext, props: PageEvent<
<nav class="tsd-navigation">
{createNavElement(props.project)}
<ul class="tsd-small-nested-navigation">
{getNavigationElements(props.project, opts).map((c) => (
{getNavigationElements(props.project, opts)?.map((c) => (
<li>{links(c, [])}</li>
))}
</ul>
Expand All @@ -161,15 +161,17 @@ export function navigation(context: DefaultThemeRenderContext, props: PageEvent<

const children = getNavigationElements(mod, opts);

if (!children.length || (!opts.fullTree && mod instanceof Reflection && !inPath(mod))) {
if (!children || (!opts.fullTree && mod instanceof Reflection && !inPath(mod))) {
return createNavElement(mod, nameClasses);
}

const childParents = mod instanceof Reflection ? [mod.getFullName()] : [...parents, mod.title];

return (
<details
class={classNames({ "tsd-index-accordion": true }, nameClasses)}
open={mod instanceof Reflection && inPath(mod)}
data-key={mod instanceof Reflection ? mod.getFullName() : [...parents, mod.title].join("$")}
data-key={childParents.join("$")}
>
<summary class="tsd-accordion-summary">
{context.icons.chevronDown()}
Expand All @@ -178,9 +180,7 @@ export function navigation(context: DefaultThemeRenderContext, props: PageEvent<
<div class="tsd-accordion-details">
<ul class="tsd-nested-navigation">
{children.map((c) => (
<li>
{links(c, mod instanceof Reflection ? [mod.getFullName()] : [...parents, mod.title])}
</li>
<li>{links(c, childParents)}</li>
))}
</ul>
</div>
Expand Down Expand Up @@ -209,7 +209,7 @@ export function navigation(context: DefaultThemeRenderContext, props: PageEvent<
} while (iter);
return false;
}
}
};

export function pageSidebar(context: DefaultThemeRenderContext, props: PageEvent<Reflection>) {
return (
Expand Down
39 changes: 25 additions & 14 deletions src/lib/utils/jsx.ts
Expand Up @@ -106,7 +106,9 @@ export function setRenderSettings(options: { pretty: boolean }) {
renderPretty = options.pretty;
}

export function renderElement(element: JsxElement | null | undefined): string {
export const renderElement = function renderElement(
element: JsxElement | null | undefined
): string {
if (!element) {
return "";
}
Expand All @@ -120,47 +122,56 @@ export function renderElement(element: JsxElement | null | undefined): string {
return renderElement(tag(Object.assign({ children }, props)));
}

const html: string[] = [];
let html = "";

if (tag !== Fragment) {
if (blockElements.has(tag) && renderPretty) {
html.push("\n");
html += "\n";
}
html.push("<", tag);
html += "<";
html += tag;

for (const [key, val] of Object.entries(props ?? {})) {
if (val == null) continue;

if (typeof val == "boolean") {
if (val) {
html.push(" ", key);
html += " ";
html += key;
}
} else {
html.push(" ", key, "=", JSON.stringify(val));
html += " ";
html += key;
html += "=";
html += JSON.stringify(val);
}
}
}

let hasChildren = false;
if (children.length) {
hasChildren = true;
if (tag !== Fragment) html.push(">");
if (tag !== Fragment) html += ">";
renderChildren(children);
}

if (tag !== Fragment) {
if (!hasChildren) {
if (voidElements.has(tag)) {
html.push("/>");
html += "/>";
} else {
html.push("></", tag, ">");
html += "></";
html += tag;
html += ">";
}
} else {
html.push("</", tag, ">");
html += "</";
html += tag;
html += ">";
}
}

return html.join("");
return html;

function renderChildren(children: JsxChildren[]) {
for (const child of children) {
Expand All @@ -169,10 +180,10 @@ export function renderElement(element: JsxElement | null | undefined): string {
if (Array.isArray(child)) {
renderChildren(child);
} else if (typeof child === "string" || typeof child === "number") {
html.push(escapeHtml(child.toString()));
html += escapeHtml(child.toString());
} else {
html.push(renderElement(child));
html += renderElement(child);
}
}
}
}
};

0 comments on commit d4098e8

Please sign in to comment.