doiuse
doiuse copied to clipboard
Performance: Cache `missingSupport` and refactor `Detector`
This PR improves the performance of doiuse in two ways, making it run 3-10 times faster:
- Cache the result of
BrowserSelection.missingSupport(), since compiling the list of missing features is an expensive operation. This improves performance when the postcss plugin is run over multiple CSS files, like when linting an entire codebase. - Refactor
Detectorto flatten and normalise all feature checks during initialization, rather than using expensiveObject.entriesoperations to parse the rules at every node in the syntax tree.
Benchmarks (from https://github.com/anandthakker/doiuse/compare/master...RJWadley:doiuse:benchmark-2):
| run | time | diff |
|---|---|---|
| Before changes | 5.3s | - |
Cache missingSupport |
4.8s | -0.5s |
Refactor of Detector |
2.2s | -3.1s |
| After both changes | 1.7s | -3.6s |
Other benchmarks:
| benchmark | before | after |
|---|---|---|
| postcss/benchmark | 233ms | 44ms |
| stylelint's benchmark | 6s | 1.5s |
| private repo: ~300 CSS files | 50s | 5s |
| private repo: ~8300 CSS files | 8m 50s | 1m 30s |
hi @clshortfuse, just a friendly bump on this PR :)