Skip to content

Expose a way to recover when using unsafeCache (for file extension changes) #8277

Closed

Description

@saifelse

Feature request

What is the expected behavior?
Renaming a file from *.js to *.ts extension should not break webpack's watch mode.

What is motivation or use case for adding/changing the behavior?
By default, webpack is configured to use "unsafeCache", which generally speeds things up, by avoiding hitting the filesystem continuously. The docs say that this is rare, but in actuality, it can be quite common when gradually porting files over from one language to another (e.g. *.js --> *.ts). When a developer ports a single file, all other developers that pull in this change are forced to restart webpack, which can be a big productivity drain.

Disabling unsafeCache is one workaround, but the performance regression is quite notable.

How should this be implemented in your opinion?
In an ideal world, I think every plugin that uses this sort of caching, should tap a compiler hook to clean up its cache so that on next compile it can recover. It's a bit odd that an object can be passed into unsafeCache to allow the caller to control this particular cache, but other caches involve reaching into internals to recover.

Note that up until #7348, all necessary information was actually available for one to write a plugin that does this recovery (and in fact broke a custom plugin that I've been using):

A quick fix that re-enables this functionality is to expose methods for resetting normalModuleFactor's dependencyCache.

Are you willing to work on this yourself?
yes

Activity

  1. sokra commented on Oct 31, 2018

    @sokra
    Member

    #8273 will add revalidation to the resolver cache, which makes it a safe cache.

    When combined with the watcher this has only minimal performance impact as file caches are tracked by the watcher.

  2. sokra commented on Oct 31, 2018

    @sokra
    Member

    The inputFileSystem is also invalidated by the watcher, so that should be safe too.

  3. sokra commented on Oct 31, 2018

    @sokra
    Member

    #8273 now also removes module.unsafeCache and defaults resolve.unsafeCache to false. All caching goes over Compiler.cache.

  4. sokra commented on Oct 31, 2018

    @sokra
    Member

    removes module.unsafeCache

    Correction: This had a too big performance hit. It defaults to unsafeCache for node_modules only

  5. webpack-bot commented on May 1, 2019

    @webpack-bot
    Contributor

    This issue had no activity for at least half a year.

    It's subject to automatic issue closing if there is no activity in the next 15 days.

  6. added
    status: stale
    on May 1, 2019
  7. webpack-bot commented on May 17, 2019

    @webpack-bot
    Contributor

    Issue was closed because of inactivity.

    If you think this is still a valid issue, please file a new issue with additional information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: stale

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions