Skip to content

module: compute module.paths lazily

Rodrigo Muino Tomonari requested to merge github/fork/kvakil/cjsLazyLoad into main

Make module.paths a getter which computes the property when it's requested. The paths property is entirely deterministically computed from the path property, and so it's not necessary to keep the relatively large paths array in memory.

On an internal application, this reduces the used heap by around 5.5%. Furthermore (although it was not a goal of this PR) it speeds up the execution time of vite --version by ~2% according to hyperfine. A similar speed improvement is observed on the internal application.

Notably, this introduces two minor changes which may be considered breaking. The obvious one is that paths is now a getter/setter and not a property. The other one is more subtle: the lazy computation means that if a user changes mod.path = X and then later invokes mod.paths, the results will reflect the updated path as opposed to the current behavior where it would reflect the original path. One way to fix the latter would be to force capturing paths before path is changed, I'm open to doing that (or some cleaner approach?) if the reviewers deem it necessary.

Merge request reports

Loading