Skip to content

Improve performance of JSDoc tag utilities#16836

Merged
3 commits merged into
masterfrom
jsdoc-perf
Jul 10, 2017
Merged

Improve performance of JSDoc tag utilities#16836
3 commits merged into
masterfrom
jsdoc-perf

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Jun 29, 2017

We currently have no good performance regression tests of large --checkJs projects, since it's a new feature. Previously the process for something like getJSDocReturnTag looked like this:

  • Look at the cache. If it is undefined, either it's not in the cache yet, or we already tried getting jsdoc tags and there were none.
  • Iterate over all JSDocs and collect an array of comments / tags.
  • Then flatMap over it:
    • At each doc comment, create a new array that filters its tags of the correct kind.
  • Get firstOrUndefined of that.

This changes it to:

  • Look at the cache. If it is null, then we've already determined that this node has no jsdoc tags.
  • If it is undefined, iterate and get tags as before.
  • Iterate over the (cached) array of tags looking for one of kind JSDocReturnTag.

@ghost ghost force-pushed the jsdoc-perf branch from c916e13 to 23a1c1c Compare June 29, 2017 18:14
Comment thread src/compiler/utilities.ts Outdated
export function getJSDocTags(node: Node): JSDocTag[] | undefined {
const cache = node.jsDocCache;
switch (cache) {
case null: // tslint:disable-line no-null-keyword
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.

Could you make comment what it means for null and undefined?

Comment thread src/compiler/utilities.ts Outdated
return result;

function getJSDocsWorker(node: Node) {
function work(node: Node) {
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.

nit: this is a bit inconsistent with how we name helper function in the codebase... I would prefer getJSDocCommentsAndTagsWorker

Comment thread src/compiler/utilities.ts Outdated

function getFirstJSDocTag(node: Node, kind: SyntaxKind): JSDocTag {
return node && firstOrUndefined(getJSDocTags(node, kind));
function getFirstJSDocTag(node: Node, kind: SyntaxKind) {
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.

nit: return type

Comment thread src/compiler/utilities.ts Outdated
return map(getJSDocs(node), doc => doc.comment);
}

export function hasJSDocParameterTags(node: FunctionLikeDeclaration | SignatureDeclaration) {
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.

nit: return type

Comment thread src/compiler/utilities.ts Outdated
}

export function getJSDocs(node: Node): (JSDoc | JSDocTag)[] {
export function getAllJSDocs(node: Node): Array<JSDoc | JSDocTag> | undefined {
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.

Q: why did we use Array<JSDoc | JSDocTag> instead (JSDoc | JSDocTag)[] ?

Comment thread src/compiler/utilities.ts
if (!cache) {
getJSDocsWorker(node);
node.jsDocCache = cache;
export function getJSDocTags(node: Node): JSDocTag[] | undefined {
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.

Q: why this function get export?

Copy link
Copy Markdown
Author

@ghost ghost Jul 6, 2017

Choose a reason for hiding this comment

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

It's needed in getJsDocTagsFromDeclarations in jsDoc.ts.

@ghost ghost mentioned this pull request Jul 6, 2017
@ghost ghost merged commit bffde58 into master Jul 10, 2017
@ghost ghost deleted the jsdoc-perf branch July 10, 2017 18:27
gcnew added a commit to gcnew/TypeScript that referenced this pull request Jul 10, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants