Skip to content

Commit

Permalink
chore: cache more info
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Sep 17, 2024
1 parent ebdff15 commit 586865e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
31 changes: 14 additions & 17 deletions src/resolve/sourceComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class SourceComponent implements MetadataComponent {
private readonly forceIgnore: ForceIgnore;
private markedForDelete = false;
private destructiveChangesType?: DestructiveChangesType;
private pathContentMap = new Map<string, string>();
private pathContentMap = new Map<string, JsonMap>();

public constructor(
props: ComponentProperties,
Expand Down Expand Up @@ -188,35 +188,32 @@ export class SourceComponent implements MetadataComponent {
public async parseXml<T extends JsonMap>(xmlFilePath?: string): Promise<T> {
const xml = xmlFilePath ?? this.xml;
if (xml) {
let contents: string;
if (this.pathContentMap.has(xml)) {
contents = this.pathContentMap.get(xml) as string;
return this.pathContentMap.get(xml) as T;
} else {
contents = (await this.tree.readFile(xml)).toString();
this.pathContentMap.set(xml, contents);
const replacements = this.replacements?.[xml] ?? this.parent?.replacements?.[xml];
const contents = (await this.tree.readFile(xml)).toString();
const value = this.parseAndValidateXML<T>(
replacements ? await replacementIterations(contents, replacements) : contents,
xml
);
this.pathContentMap.set(xml, value);
return value;
}

const replacements = this.replacements?.[xml] ?? this.parent?.replacements?.[xml];
return this.parseAndValidateXML<T>(
replacements ? await replacementIterations(contents, replacements) : contents,
xml
);
}
return {} as T;
}

public parseXmlSync<T extends JsonMap>(xmlFilePath?: string): T {
const xml = xmlFilePath ?? this.xml;
if (xml) {
let contents: string;
if (this.pathContentMap.has(xml)) {
contents = this.pathContentMap.get(xml) as string;
return this.pathContentMap.get(xml) as T;
} else {
contents = this.tree.readFileSync(xml).toString();
const contents = this.parseAndValidateXML(this.tree.readFileSync(xml).toString(), xml);
this.pathContentMap.set(xml, contents);
return contents as T;
}

return this.parseAndValidateXML(contents, xml);
}
return {} as T;
}
Expand Down Expand Up @@ -287,7 +284,7 @@ export class SourceComponent implements MetadataComponent {
}

private parse<T extends JsonMap>(contents: string): T {
const parsed = parser.parse(String(contents)) as T;
const parsed = parser.parse(contents) as T;
const [firstElement] = Object.keys(parsed);
if (firstElement === this.type.name) {
return parsed;
Expand Down
6 changes: 1 addition & 5 deletions test/resolve/forceIgnore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ describe('ForceIgnore', () => {
expect(fi.accepts(join('force-app', 'main', 'default', 'classes'))).to.be.true;
});

/**
* TODO: Rework when approach to default patterns changes. We should be able
* to generally test the defaults system.
*/
describe('Defaults with new parser', () => {
let forceIgnore: ForceIgnore;
const root = join('some', 'path');
Expand All @@ -84,7 +80,7 @@ describe('ForceIgnore', () => {
forceIgnore = new ForceIgnore();
});

// the example's index here is specific to the rules order in ForceIgnore.DEFAULT_IGNORE
// these examples test the default behaviors
const forceIgnoreExamples = ['abc.dup', '.xyz', 'package2-descriptor.json', 'package2-manifest.json'];
forceIgnoreExamples.map((ignore) => {
it(`Should ignore files starting with a ${ignore}`, () => {
Expand Down

2 comments on commit 586865e

@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: 586865e Previous: ebdff15 Ratio
eda-componentSetCreate-linux 237 ms 240 ms 0.99
eda-sourceToMdapi-linux 2290 ms 2409 ms 0.95
eda-sourceToZip-linux 1899 ms 1897 ms 1.00
eda-mdapiToSource-linux 3024 ms 2923 ms 1.03
lotsOfClasses-componentSetCreate-linux 429 ms 434 ms 0.99
lotsOfClasses-sourceToMdapi-linux 3807 ms 3746 ms 1.02
lotsOfClasses-sourceToZip-linux 3224 ms 3277 ms 0.98
lotsOfClasses-mdapiToSource-linux 3616 ms 3631 ms 1.00
lotsOfClassesOneDir-componentSetCreate-linux 766 ms 761 ms 1.01
lotsOfClassesOneDir-sourceToMdapi-linux 6659 ms 6582 ms 1.01
lotsOfClassesOneDir-sourceToZip-linux 5804 ms 5925 ms 0.98
lotsOfClassesOneDir-mdapiToSource-linux 6570 ms 6652 ms 0.99

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: 586865e Previous: ebdff15 Ratio
eda-componentSetCreate-win32 664 ms 736 ms 0.90
eda-sourceToMdapi-win32 4582 ms 4826 ms 0.95
eda-sourceToZip-win32 3219 ms 3311 ms 0.97
eda-mdapiToSource-win32 6082 ms 6432 ms 0.95
lotsOfClasses-componentSetCreate-win32 1286 ms 1315 ms 0.98
lotsOfClasses-sourceToMdapi-win32 8359 ms 8429 ms 0.99
lotsOfClasses-sourceToZip-win32 5338 ms 5525 ms 0.97
lotsOfClasses-mdapiToSource-win32 8505 ms 8594 ms 0.99
lotsOfClassesOneDir-componentSetCreate-win32 2234 ms 2134 ms 1.05
lotsOfClassesOneDir-sourceToMdapi-win32 14810 ms 14095 ms 1.05
lotsOfClassesOneDir-sourceToZip-win32 9949 ms 9293 ms 1.07
lotsOfClassesOneDir-mdapiToSource-win32 15320 ms 14182 ms 1.08

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

Please sign in to comment.