Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Rule Performance Statistics #108

Merged
merged 33 commits into from
Oct 11, 2023
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
69c143e
feat: Rule Performance Dashboard
mnkiefer Mar 13, 2023
4c76a79
Update image
mnkiefer Mar 13, 2023
fbddd43
Clean-up
mnkiefer Mar 13, 2023
df315c7
Update designs/2023-rule-performance-dashboard/README.md
mnkiefer Mar 19, 2023
d4162b7
Update formatter name
mnkiefer Mar 19, 2023
0b64114
Update formatter name
mnkiefer Mar 19, 2023
a7962a8
Merge branch 'htmlCharts' of https://github.com/mnkiefer/rfcs into ht…
mnkiefer Mar 19, 2023
417f95f
Update summary
mnkiefer Mar 30, 2023
5f36a49
Updated text, pending sample implementation update
mnkiefer Apr 8, 2023
7335add
Update json structure
mnkiefer Apr 8, 2023
9afa76d
Updated rfc according based on sample implementation
mnkiefer Apr 10, 2023
72d903f
Fix refs
mnkiefer Apr 10, 2023
f5c2b84
Add pass timing
mnkiefer May 11, 2023
b8cc2f8
Elaborate on timing total
mnkiefer May 11, 2023
ddf8996
Removed vscode settings file
mnkiefer May 11, 2023
67a3be7
Add specific implementation details apart from POC
mnkiefer Jun 4, 2023
e92980b
Updated sample data
mnkiefer Jun 4, 2023
9571c7b
Text snippets as markdown
mnkiefer Jun 4, 2023
d69f6ea
Update dashboard
mnkiefer Jun 4, 2023
ba7acfd
Update designs/2023-rule-performance-dashboard/README.md
mnkiefer Jun 17, 2023
ef239c2
Updated rfc
mnkiefer Jul 23, 2023
d68c9d8
Update designs/2023-rule-performance-dashboard/README.md
mnkiefer Jul 24, 2023
e4e1c7c
Rename and update rfc
mnkiefer Jul 24, 2023
051e8c9
Merge branch 'htmlCharts' of https://github.com/mnkiefer/rfcs into ht…
mnkiefer Jul 24, 2023
22c363e
Update fix.passes structure
mnkiefer Aug 23, 2023
ebe0ce7
Update passes[] structure
mnkiefer Aug 27, 2023
148fbbd
Describe time helper functions
mnkiefer Sep 16, 2023
034d033
Update fixPasses
mnkiefer Sep 26, 2023
834805f
Update README.md
mnkiefer Sep 26, 2023
f62b3c5
Remove directives, violations
mnkiefer Sep 26, 2023
8d644a6
Update according to review
mnkiefer Oct 1, 2023
b229c58
Update designs/2023-rule-performance-statistics/README.md
mnkiefer Oct 5, 2023
12d61cd
Update designs/2023-rule-performance-statistics/README.md
mnkiefer Oct 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 53 additions & 14 deletions designs/2023-rule-performance-dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
- RFC PR: <https://github.com/eslint/rfcs/pull/108>
- Authors: Mara Nikola Kiefer (@mnkiefer)
mnkiefer marked this conversation as resolved.
Show resolved Hide resolved

# Rule Performance Statistics
# Performance Statistics

## Summary

<!-- One-paragraph explanation of the feature. -->

This document describes how to expose ESLint's [`TIMING`](https://eslint.org/docs/latest/extend/custom-rules#profile-rule-performance) information as well as some general runtime statistics to the [formatters](https://eslint.org/docs/latest/use/formatters/) when using the `--stats` flag.
This document describes the new flag `--stats`, which adds a series of runtime statistics such as parse-, fix-, and lint-times ([`TIMING`](https://eslint.org/docs/latest/extend/custom-rules#profile-rule-performance)) as well the number of directives, fix passes, suppressions, and violations to the final result object.

> **Optional:**
> A special [formatter](https://eslint.org/docs/latest/use/formatters/) `html-rule-performance` enables easy ingestion and interpretation of this data in form of a dashboard.

## Motivation

<!-- Why are we doing this? What use cases does it support? What is the expected
outcome? -->

Analysing rule performance currently requires additional scripting to collect/extract more *granular* timing data (lint time per file per rule):
Analyzing rule performance currently requires additional scripting to collect/extract more *granular* timing data (lint time per file per rule):

1. Running ESLint per rule, per file and then collecting the file/rule time data output:

Expand All @@ -34,8 +37,9 @@ In addition, one needs to create an overview for an effective presentation of th

It would be more *convenient and shareable* to have:

1. The **timing data** ESLint already collects exposed to the formatters
2. A **built-in formatter** for that data
1. The **timing data** ESLint already collects exposed to the formatters.
2. Also collect and expose [other statistics](https://github.com/eslint/eslint/issues/14597#issuecomment-1003863524).
> [optional] 3. A **built-in formatter** for that data

## Detailed Design

Expand All @@ -54,19 +58,48 @@ The *proof-of-concept* can be found at:

### ESLint *timing* exposed

Exposure of the timing object requires only a few changes in the Linter and CLI engline.
Exposure of the timing object requires only a few changes to files in the Linter (in `lib/linter`) and ESLint itself (`lib/eslint`) as most of the information is already present but just needs to be persistet.

**Timing: `lint`**:

The overall lint time that is spent on a file. This includes `parse-`, `timing-`running all of the rules as well as any fixes.

**Timing: `parse`**

The time that is spent when parsing a file, that is when [`parse()`](#timing-parse) or `parseForEslint()` is called (in [linter](https://github.com/eslint/eslint/blob/main/lib/linter/linter.js#L808)).

**Timing: `rules`**:

The timing is already collected in `lib/linter/timing.js`. Note, that the function requires the extra input paramter `filename`. For the function itself, the only change is that we now *persist* that information in the `timing` object, which stores the detailed *per file per rule* lint times under the **rules** key.
This is essentially the same as the rules timing already collected in `lib/linter/timing.js`. To persist this, the function requires the extra input parameter `filename` to be able to store more detailed *per file per rule* lint times under the **rules** key.

The linter `lib/linter/linter.js` retrieves the timing data only when `TIMING` is enabled (i.e. from the ESLint CLI).
**Pass number**:
The number of [fixes](https://eslint.org/docs/latest/use/command-line-interface#fix-problems) successfully applied to a file (see [linter](
https://github.com/eslint/eslint/blob/main/lib/linter/linter.js#L1987)).

Finally, we append the new [timing data](#timing-data) to the *Lint Report* in the CLI engine `lib/cli-engine/cli-engine.js` such that they are accessible to the formatters:
- `lintTime` (ms): Lint time of file
- `lintOrder` (order number): Lint order of file
- `lintTimePerRule` (ms): Lint time of file per rule
**Violations, Suppressions, Directives**:
See [this issue comment](https://github.com/eslint/eslint/issues/14597#issuecomment-1003863524) for a description/motivation of each.

Below is an excerpt of a sample for the 5th file that was linted in the sample project:

```json
// Numbers based on implementation sample (TO BE UPDATED)
{
// Result object properties
"stats": {
"fixPasses": 3,
"timing": {
mnkiefer marked this conversation as resolved.
Show resolved Hide resolved
"lint": 123,
"parse": 123,
"fix": 456,
"rules": {
"semi": 123,
"quotes": 123
}
}
}
}
```
<!--
```json
{
...
Expand All @@ -89,10 +122,15 @@ Below is an excerpt of a sample for the 5th file that was linted in the sample p
"fileSize": 312
}
```
-->

### Formatter `html-rule-performance`

> **Optional:**
> ### Formatter `html-rule-performance` [optional]
> ```
> < IMAGE/DESCRIPTION (TO BE UPDATED) >
> ```

<!-- TEXT/IMAGE TO BE UPDATED
<img width="600" alt="rule-performance-dashboard" src="./htmlCharts.png">


Expand All @@ -103,6 +141,7 @@ The **Rule Performance Dashboard** consists of two parts:
2. On the right hand side (**2**), we have the charts created by the [Chart.js](https://www.chartjs.org/) library. The first chart (**2a**) is a pie chart of the usual `TIMING` performance results the user is used to seeing from ESLint's stdout. The second chart (**2c**) contains the more detailed *per file per rule* information for each file (x-axis) and lint time (y-axis, left, line chart) per rule as well as the the respective file size (y-axis, right, bar chart).The file sizes and the total lint times are shown in the background in gray, while the individual rule lint times are shown as colored lines. Note, that both charts will update on changes to the rule selection checkbox menu (**2b**, top right corner of the screen) such that one can easily view and compare different rule (times) across all files, which can help to detect more intricate performance issues that may be overlooked otherwise (based on rule reports or average values across entire runs only).

The above dashboard stems from an ESLint run on the [sample project](https://github.com/mnkiefer/eslint-samples) with 28 `*.js` files of valid/invalid [recommended rules](https://eslint.org/docs/latest/rules/) examples (as taken from [ESLint's Rule Documentation](https://eslint.org/docs/latest/rules/) examples).
-->

## Documentation

Expand Down