react / react/react

Custom React-specific metadata format

Open
#22,540 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Developer Tools Size: Large Type: Discussion
Dominant language
JavaScript
Stars
251k
Forks
51.4k
Avg merge
2d 4h
Merged PRs (30d)
53

Description

The recent DevTools "named hooks" feature has been heavily optimized since its initial launch. There are some additional optimizations that we could consider (see the first comment below) but I believe the single biggest remaining bottleneck is downloading and parsing of large source map files.

Using Facebook as a case study, over 65% of the time spent parsing hook names is downloading the source-map files:
image

A significant portion of this time is spent on the generating the source map on the server:
image

Perhaps this could be optimized further, but at some point- we'll still have to download and parse a potentially large file.

Can we avoid relying on the source map entirely?

We aren't using source maps in the typical way. (We aren't displaying the original source code.) So the majority of the data contained in the source-map is useless to us. We've experimented with extending the source map so that we didn't have to parse the original code, but the biggest bottleneck (based on testing) is actually generating and downloading the source-map so this only helps a little.

What if we pre-computed hooks metadata (during compilation) and wrote it to a separate file that gets bundled along like a source map. We could generate this metadata for the compiled code, rather than the source code, so we wouldn't need to map anything at runtime. I don't have exact figures on how much faster this would be, but I estimate it would reduce the source-map file size by an order of magnitude which could have a pretty large impact on the overall performance.

If this custom metadata file is successful, we could also store some additional (lightweight) information in it such as component display names.

Adding additional metadata to this file/format should be done in a backwards-compatible way if at all possible. Still, the metadata format should be versioned in the event that a backwards breaking change occurred.

What if this metadata was unavailable?

This would be entirely opt-in. DevTools would fall back to loading and parsing the complete source-map if this custom metadata was unavailable.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the named hooks feature in the React DevTools changelog and the source-map extension discussion in issue #21782. Trace how DevTools currently loads and parses source maps; done would mean an opt-in, versioned custom metadata format with backwards-compatible handling and complete source-map fallback when the metadata is unavailable.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
devtools, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.