-
Notifications
You must be signed in to change notification settings - Fork 887
Conversation
As a side note: Maybe we could create a tslint rule for that? Maybe in a separate project as this would not be relevant for end users of tslint? |
return modifiers.some((m) => { | ||
return modifierKinds.some((k) => m.kind === k); | ||
}); | ||
for (const modifier of modifiers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this changed?
const minEnd = Math.min(interval.endPosition, failure.getEndPosition().getPosition()); | ||
return maxStart <= minEnd; | ||
}); | ||
const failureStart = failure.getStartPosition().getPosition(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change?
/** | ||
* Finds a child of a given node with a given kind. | ||
* Note: This uses `node.getChildren()`, which does extra parsing work to include tokens. | ||
*/ | ||
export function childOfKind(node: ts.Node, kind: ts.SyntaxKind): ts.Node | undefined { | ||
return find(node.getChildren(), (child) => child.kind === kind); | ||
export function childOfKind(node: ts.Node, kind: ts.SyntaxKind, sourceFile?: ts.SourceFile): ts.Node | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change?
I'm wary of making perf improvements without a performance profiler indicating a problem or a benchmark improvement. |
I can't speak to whether or not there is a performance issue that needs to be fixed, but for loops seem to nearly always be faster than method invocations. A simple test: http://jsperf.com/array-some-vs-loop |
This reverts commit 8cc0908.
@ericanderson you're right at the moment, but eventually there will be no difference, hopefully. However, that specific commit was not intended to be included in this or any other PR, so I reverted it. |
@nchen63 You're right, I should have done the profiling before changing everything. I'll close this PR and maybe you can even close #1747. |
@ajafff thanks for looking into that |
PR checklist
New feature, bugfix, orenhancementWhat changes did you make?
This is a first attempt to improve performance of core rules. It's basically #1747 ... search for
\.get((Full)?Text|Start|(LeadingTrivia)?Width|(First|Last)Token|Child(ren|Count))\(\)|\.getChildAt\(\d+\)
and pass SourceFile as parameter.To keep the diff somewhat small, I chose to submit the changes in chunks as I progress. So here we go from
alignRule
untilnoDefaultExportRule
.Of course this is only the low hanging fruit. When I find the time, I will look at the rules in more detail.