anandthakker / doiuse

:bomb: Lint CSS for browser support against caniuse database.
MIT License
1.23k stars 50 forks source link

Performance: Cache `missingSupport` and refactor `Detector` #182

Open cmrn opened 5 months ago

cmrn commented 5 months ago

This PR improves the performance of doiuse in two ways, making it run 3-10 times faster:

  1. 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.
  2. Refactor Detector to flatten and normalise all feature checks during initialization, rather than using expensive Object.entries operations 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
cmrn commented 1 month ago

hi @clshortfuse, just a friendly bump on this PR :)