stencil icon indicating copy to clipboard operation
stencil copied to clipboard

fix(compiler): Re-enable build cache

Open George-Payne opened this issue 2 years ago • 0 comments

  • uncomment cache write to disk
  • add buildCacheDirName config option to prevent clash with ScreenshotConnector

Pull request checklist

Please check if your PR fulfills the following requirements:

  • [ ] Tests for the changes have been added (for bug fixes / features)
  • [ ] Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • [x] Build (npm run build) was run locally and any changes were pushed
  • [x] Unit tests (npm test) were run locally and passed
  • [x] E2E Tests (npm run test.karma.prod) were run locally and passed
  • [x] Prettier (npm run prettier) was run locally and passed

Pull request type

Please check the type of change your PR introduces:

  • [x] Bugfix
  • [ ] Feature
  • [ ] Refactoring (no functional changes, no api changes)
  • [x] Build related changes
  • [ ] Documentation content changes
  • [ ] Other (please describe):

What is the current behavior?

Issue 1: Currently, the build cache is being populated, but not written to disk, so is not picked up in subsequent builds.

The line of code here: https://github.com/ionic-team/stencil/blob/main/src/compiler/build/write-build.ts#L24

Was commented out in this commit: https://github.com/ionic-team/stencil/commit/63595bc540db9aa85295f5a8dc8738beb2a37611

I can't see why it was commented out, as the cache seems to work perfectly, possibly a mistake in refactoring, or some leftover testing?

Issue 2:

ScreenshotConnector also uses the cacheDir for it's cache, but a build clears out the cache here: https://github.com/ionic-team/stencil/blob/c0aeac1176c474f4e0935e40f3944433f5c24860/src/compiler/cache.ts#L20

What is the new behavior?

Uncommenting the line that writes the cache to disk re-enables the cache.

This offers considerable speedup in large (~200 component) projects:

Before: ~71s (average of three runs [81.62s, 64.27s, 69.29s]) After: ~38s (average of three runs [39.37s, 38.11s, 37.98s]) (with cache populated)

New config option buildCacheDirName with default "build"

Places the cache in ${cacheDir}/${buildCacheDirName} , matching the pattern of ScreenshotConnector (${cacheDir}/${screenshotCacheFileName}). This means only .stencil/build is wiped when the cache is cleared, leaving the screenshot connector cache alone.

Does this introduce a breaking change?

  • [ ] Yes
  • [ ] No
  • [x] Don't think so

Testing

See time measurements above

Other information

Slack discussion: https://stencil-worldwide.slack.com/archives/C79EANFL7/p1657182204289689

George-Payne avatar Jul 07 '22 12:07 George-Payne