Skip to content

Fix a perf issue where API Extractor would reread package.json - #236

Merged
Pete Gonzalez (octogonz) merged 6 commits into
masterfrom
pgonzal/api-extractor-perf-fix
Jun 16, 2017
Merged

Pete Gonzalez (octogonz) merged 6 commits into
masterfrom
pgonzal/api-extractor-perf-fix

Conversation

@octogonz

Copy link
Copy Markdown
Collaborator

When determining which NPM package a source file belongs to, API Extractor was repeatedly reading the same package.json files. This PR adds a cache to avoid performance issues.

* and retrieving the name of the package. The results are cached.
*/
export default class PackageJsonLookup {
private _tryFindPackagePathUpwardsCache: Map<string, string>;

@qz2017 QZ (qz2017) Jun 16, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_tryFindPackagePathUpwardsCache [](start = 10, length = 31)

How about naming those two as packagePathCache and packageNameCache? #Resolved

* This class provides methods for finding the nearest "package.json" for a folder
* and retrieving the name of the package. The results are cached.
*/
export default class PackageJsonLookup {

@qz2017 QZ (qz2017) Jun 16, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PackageJsonLookup [](start = 21, length = 17)

If this one is reusable, please add a test class as well. #Resolved

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This code is already heavily covered by the other unit tests, but I can add a dedicated test as well.


In reply to: 122495182 [](ancestors = 122495182)

@qz2017

QZ (qz2017) commented Jun 16, 2017 •

Copy link
Copy Markdown
Contributor

:shipit:

Approved with PullApprove

// represent "undefined".
let result: string = this._tryFindPackagePathUpwardsCache.get(currentPath);
if (result !== undefined) {
return result === null ? undefined : result; // tslint:disable-line: no-null-keyword

@qz2017 QZ (qz2017) Jun 16, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

result === null ? undefined : result [](start = 13, length = 36)

This can be put in a function. Two copies of the same code here. #Resolved

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

QZ (@qz2017) actually the code is not the same. However since that wasn't obvious, I suppose it would be more readable to move it into a function. :-)


In reply to: 122495414 [](ancestors = 122495414)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I chatted with some other people about this, and it turns out that you CAN store 'undefined' in a Map. You just have to use the has() function (i.e. two lookups) to handle that case.


In reply to: 122506976 [](ancestors = 122506976,122495414)

@octogonz

Pete Gonzalez (octogonz) commented Jun 16, 2017 •

Copy link
Copy Markdown
Collaborator Author

:shipit:

Approved with PullApprove Approved with PullApprove

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants