question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature]: Introduce a "lazy" haste-map implementation

See original GitHub issue

🚀 Feature Proposal

This proposal is aimed at the react-native developer community. It introduces an experimental crawler to jest-haste-map, which should dramatically speed up metro start times and reduce resource consumption (CPU, memory, disk).

The new crawler is named lazy, and should reside next to the node and watchman crawlers. Unlike node and watchman, lazy doesn’t eagerly collect file metadata. Instead, it reads metadata on demand, as files are requested.

This breaks the design of Haste module loading, since there is no longer an in-memory listing of provided modules. In a react-native context, that’s ok, as almost no one there uses Haste.

The working theory is that the file graph generated on-demand by lazy (for bundling) will be much smaller than the entire monorepo file graph, and will therefore use fewer resources and take less time.

To validate this, we need a prototype implementation and a set of measurable experiments which look at CPU time, memory usage, disk reads/writes, time to create a bundle, and time to start a bundle server and deliver a bundle to a waiting app.

The metadata found by lazy should be cached, just as watchman and node data is cached.

lazy must support file-watching on files it has encountered, to ensure that metro (and other jest-haste-map clients) remain up to date.

Motivation

metro uses jest-haste-map to crawl the monorepo file-system. It gathers metadata on each file and watches for changes so it can keep the metadata up-to-date. The metadata includes things like a file hash and info about haste annotations within the file (e.g. @providesModule). The haste annotations allow a module to depend on another without using an explicit import or require statement.

metro crawls the file-system synchronously when it is launched, before it bundles or starts a bundle server. In large monorepos, crawling takes a long time and uses a lot of CPU, memory and disk resources. jest-haste-map uses caching to alleviate this. Even still, the cached data can take several gigabytes of memory. At this size, the haste map causes watchman to become unresponsive or crash at times.

Haste, as a module loading system, is not widely used by the react-native developer community. Yet, every developer pays the cost to run it on their machines and in CI loops.

metro recently landed a PR which lets developers replace the default haste map implementation with their own code. Using this, we can customize jest-haste-map to use the lazy crawler.

Example

No response

Pitch

It is a new crawler and therefore must be in jest-haste-map alongside existing crawlers.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

1reaction
SimenBcommented, Feb 26, 2022

PR very much welcome adding an alternative crawler! 👍

0reactions
github-actions[bot]commented, May 28, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest-haste-map | Yarn - Package Manager
Jest can be used in projects that use parcel-bundler to manage assets, styles, and compilation similar to webpack. Parcel requires zero configuration. Refer...
Read more >
metro-config | React Native Developer Tools
Metro currently does not implement tree shaking, i.e. it does not attempt to remove unused code from the JS bundle. For instance, given...
Read more >
2016 in Jest
lazyspec can help you create smoke tests quickly if you are introducing tests to an existing codebase. Patrick Stapfer did a lightning talk ......
Read more >
Implementing Laziness - Brown CS
Recall that in a lazy language, the argument to a function—which includes the named ... To implement caching, we modify the interpreter as...
Read more >
Third Party Software 5.2.1 - Confluent
an implementation of USocketFactory using netcat, BSD-3-Clause ... babel-plugin-syntax-trailing-function-commas, MIT ... jest-haste-map, BSD-3-Clause.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found