refactor(cache): simplify noCache
condition
#362
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Greatly simplify the
noCache
condition intscache
-- basically most of the code is not used and can be removed or can early return in the case that there is no cache.clean
method #358 's simplificationsDetails
if there is no cache, we don't need to do any operations on a cache at all, so we can just totally skip all the cache operations and return early
clean: true
a more optimal choice for smaller projects, as the FS usage when writing to cache may be slower than the small amount of compilation and type-checking required in small projectsto start, from the
constructor
, the only necessary piece whennoCache
is the dependency treewalkTree
andsetDependency
to function, but otherwise is unused whennoCache
noCache
, but that is saved for potential future work and not part of this PRconstructor
as its previous ordering within theconstructor
does not actually matternoCache
instead of doing all the cache-related actions, since they're not needed when there is no cachecacheDir
or any hashes etc since they're not usedclean
only usescachePrefix
andcacheRoot
, which are already set, and does not usecacheDir
init
the cache as it's not usedinit
right after its prereqs are done, i.e. settingcacheDir
,hashOptions
, etcisDirty
is literally never called whennoCache
from there, since we don't call
checkAmbientTypes
orinit
whennoCache
(the constructor is the only place they are called and they are bothprivate
), we can entirely remove theirnoCache
branchescheckAmbientTypes
, we just remove the tiny if block that setsambientTypesDirty
, as, well, "dirty" isn't used when there is no cacheinit
, this means we can entirely remove the creation ofNoCache
, which isn't needed when there is no cacheNoCache
CONTRIBUTING.md
in
done
(which ispublic
), we can also simply skip rolling caches and early return when there is no cachethe only other tiny change is the non-null assertions for
ambientTypes
andcacheDir
ambientTypes
etc to workaround this, but thought it better to match existing code style and not add new thingsambientTypes
andcacheDir
could benull
, this is only if there is no cache, in which case, they are never usedPotential Future Work
noCache
by exploring if the wholedependencyTree
could be removed in that caseclean
, as it actually may be more performant in the case of smaller projects