Skip to content

Commit

Permalink
fix(perf): fewer adapter classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jun 25, 2024
1 parent 84a0630 commit 63ce40e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
9 changes: 1 addition & 8 deletions src/resolve/adapters/baseSourceAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ export abstract class BaseSourceAdapter implements SourceAdapter {
return this.populate(path, component, isResolvingSource);
}

/**
* Control whether metadata and content metadata files are allowed for an adapter.
*/
public allowMetadataWithContent(): boolean {
return this.metadataWithContent;
}

/**
* If the path given to `getComponent` is the root metadata xml file for a component,
* parse the name and return it. This is an optimization to not make a child adapter do
Expand Down Expand Up @@ -114,7 +107,7 @@ export abstract class BaseSourceAdapter implements SourceAdapter {
return folderMetadataXml;
}

if (!this.allowMetadataWithContent()) {
if (!this.metadataWithContent) {
return parseAsContentMetadataXml(this.type)(path);
}
}
Expand Down
23 changes: 16 additions & 7 deletions src/resolve/metadataResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,19 @@ export class MetadataResolver {
}
const type = resolveType(this.registry)(this.tree)(fsPath);
if (type) {
const adapter = new SourceAdapterFactory(this.registry, this.tree).getAdapter(type, this.forceIgnore);
// short circuit the component resolution unless this is a resolve for a
// source path or allowed content-only path, otherwise the adapter
// knows how to handle it
const shouldResolve =
isResolvingSource ||
parseAsRootMetadataXml(fsPath) ||
!parseAsContentMetadataXml(this.registry)(fsPath) ||
!adapter.allowMetadataWithContent();
return shouldResolve ? adapter.getComponent(fsPath, isResolvingSource) : undefined;
if (
!isResolvingSource &&
!parseAsRootMetadataXml(fsPath) &&
parseAsContentMetadataXml(this.registry)(fsPath) &&
typeAllowsMetadataWithContent(type)
) {
return;
}
const adapter = new SourceAdapterFactory(this.registry, this.tree).getAdapter(type, this.forceIgnore);
return adapter.getComponent(fsPath, isResolvingSource);
}

if (isProbablyPackageManifest(this.tree)(fsPath)) return undefined;
Expand Down Expand Up @@ -439,3 +442,9 @@ const pathIncludesDirName =
* @param fsPath File path of a potential metadata xml file
*/
const parseAsRootMetadataXml = (fsPath: string): boolean => Boolean(parseMetadataXml(fsPath));

/** decomposed and default types are `false`, everything else is true */
const typeAllowsMetadataWithContent = (type: MetadataType): boolean =>
type.strategies?.adapter !== undefined && // another way of saying default
type.strategies.adapter !== 'decomposed' &&
type.strategies.adapter !== 'default';
5 changes: 0 additions & 5 deletions src/resolve/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,4 @@ export type SourceAdapter = {
* @param isResolvingSource Whether the path to resolve is a single file
*/
getComponent(fsPath: SourcePath, isResolvingSource?: boolean): SourceComponent | undefined;

/**
* Whether the adapter allows content-only metadata definitions.
*/
allowMetadataWithContent(): boolean;
};
1 change: 0 additions & 1 deletion test/resolve/registryTestUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export class RegistryTestUtil {
}
getAdapterStub.withArgs(entry.type).returns({
getComponent: (path: SourcePath) => componentMap[path],
allowMetadataWithContent: () => entry.allowContent ?? false,
});
}
}
Expand Down

2 comments on commit 63ce40e

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 63ce40e Previous: 3a1ca98 Ratio
eda-componentSetCreate-linux 192 ms 177 ms 1.08
eda-sourceToMdapi-linux 1963 ms 1948 ms 1.01
eda-sourceToZip-linux 1795 ms 1787 ms 1.00
eda-mdapiToSource-linux 2761 ms 2845 ms 0.97
lotsOfClasses-componentSetCreate-linux 360 ms 421 ms 0.86
lotsOfClasses-sourceToMdapi-linux 3746 ms 3689 ms 1.02
lotsOfClasses-sourceToZip-linux 2997 ms 3027 ms 0.99
lotsOfClasses-mdapiToSource-linux 3495 ms 3481 ms 1.00
lotsOfClassesOneDir-componentSetCreate-linux 621 ms 632 ms 0.98
lotsOfClassesOneDir-sourceToMdapi-linux 6528 ms 6482 ms 1.01
lotsOfClassesOneDir-sourceToZip-linux 5530 ms 5582 ms 0.99
lotsOfClassesOneDir-mdapiToSource-linux 6397 ms 6250 ms 1.02

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 63ce40e Previous: 3a1ca98 Ratio
eda-componentSetCreate-win32 378 ms 397 ms 0.95
eda-sourceToMdapi-win32 3434 ms 3421 ms 1.00
eda-sourceToZip-win32 2668 ms 2712 ms 0.98
eda-mdapiToSource-win32 5561 ms 5614 ms 0.99
lotsOfClasses-componentSetCreate-win32 888 ms 897 ms 0.99
lotsOfClasses-sourceToMdapi-win32 7431 ms 7564 ms 0.98
lotsOfClasses-sourceToZip-win32 4684 ms 4761 ms 0.98
lotsOfClasses-mdapiToSource-win32 7436 ms 7444 ms 1.00
lotsOfClassesOneDir-componentSetCreate-win32 1473 ms 1504 ms 0.98
lotsOfClassesOneDir-sourceToMdapi-win32 13373 ms 13639 ms 0.98
lotsOfClassesOneDir-sourceToZip-win32 8636 ms 8869 ms 0.97
lotsOfClassesOneDir-mdapiToSource-win32 13372 ms 13646 ms 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.