Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite DeltaBundler garbage collection (#820)
Summary: Pull Request resolved: #820 See also: microsoft/rnx-kit#1514 Rewrites traverseDependencies (the core algorithm of DeltaBundler) to run in two distinct phases: 1. Module transformation + dependency discovery/diffing. 2. Garbage collection. Modules that are trivially unreachable (inverse dependency count decreases to zero) are deleted during (1); the rest ( = unreachable modules in dependency cycles) are deleted during (2). By collecting cycles in a separate pass instead of kicking off nested traversals during the dependency diffing pass, the algorithm becomes easier to reason about, and we gain the ability to optionally skip GC (in future work) because all the GC state is stored in the graph (and not on the traversal stack). The garbage collection code is adapted from the Synchronous Cycle Collection algorithm described in: > David F. Bacon and V. T. Rajan. 2001. Concurrent Cycle Collection in Reference Counted Systems. In Proceedings of the 15th European Conference on Object-Oriented Programming (ECOOP '01). Springer-Verlag, Berlin, Heidelberg, 207–235. --- As part of this rewrite we also make the handling of async imports under `experimentalImportBundleSupport: true` more sound and tested, at least as far as `traverseDependencies` goes. Several of the new tests under "lazy traversal of async imports" were failing before this diff. Note that there a few remaining problems with this experimental feature, which will need to be fixed in separate work: 1. The HMR protocol does not sync changes to `importBundleNames` between the client and server, so any newly added async dependencies in a Fast Refresh'd module will (still) break at runtime. 2. A module's out-edges are keyed on the unresolved dependency paths only, so a parallel async+sync pair of dependencies from A --> B will result in either an async or sync edge being recorded, depending on their order in the dependencies array. This will need fixing in both DeltaBundler and `collectDependencies`. Reviewed By: robhogan Differential Revision: D36403390 fbshipit-source-id: 6ec32fc5f5d4f4faef3dac78ce27129695d761f4
- Loading branch information