Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import React Concurrent Mode Profiler #37

Closed
wants to merge 131 commits into from

Conversation

taneliang
Copy link
Member

@taneliang taneliang commented Aug 17, 2020

Summary

This PR imports the concurrent mode profiler project into packages/react-devtools-scheduling-profiler, with history 🎉

image

Broadly follows the approach of facebook#16381.

Resolves MLH-Fellowship/scheduling-profiler-prototype#134.

Import Details

Notes

  • Our new build and start scripts were failing with this error: No "exports" main resolved in @babel/helper-compilation-targets/package.json babel/babel#11216 (comment). I've followed the maintainer's recommendation and updated all @babel/* packages across the repository, excluding fixtures. We can easily revert this if there's a better solution.
  • Webpack config is based on react-devtools-shell's.
  • Dependencies used have been upgraded to the latest versions. css-loader config differences can be backported into the other devtools packages later.
  • Unlike the other devtools packages, we generate our index.html file into the dist folder using HtmlWebpackPlugin. This means that the dist folder can be served directly, and can likely be deployed to Vercel without a need for a now.json file.

Major differences with the version in the original repo:

  • Parcel has been replaced with Webpack for better integration with the rest of the React repo.
  • The sample profile auto-loaded in DEV for convenience is now dynamically imported. It's now trivial to add a demo profile feature for end users (Craft a custom performance profile to "demo" scheduling-profiler-prototype#82).
  • index.html is now automatically generated by html-webpack-plugin instead of being based on a template file.
  • Page title has been renamed to "React Concurrent Mode Profiler".

Process

Similar to facebook#16381, the goal of this import is to preserve history from https://github.com/MLH-Fellowship/scheduling-profiler-prototype. Verified that git log --follow worked as expected on imported files.

Prepare fork for merge

mkdir profiler-merge
cd profiler-merge

git init .
git commit -m "Initializing empty merge repo" --allow-empty  

git remote add -f profiler-merge git@github.com:MLH-Fellowship/scheduling-profiler-prototype.git
git merge profiler-merge/master --allow-unrelated-histories

mkdir -p packages/react-scheduling-profiler
mv * packages/react-devtools-scheduling-profiler
mv .* packages/react-devtools-scheduling-profiler
mv packages/react-devtools-scheduling-profiler/.git .
# Commit

Import into React

cd ../react

git remote add profiler-importable ../profiler-merge
git fetch --all

git checkout -b scheduling-profiler-import
git merge --allow-unrelated-histories profiler-importable/importable
git remote rm profiler-importable

Checklist

  • Remove extraneous project-specific files (.github, .vscode, etc)
  • Integrate package.json with monorepo and remove yarn.lock
  • Fix build/start
  • Integrate with linter
  • Fix lint
  • Integrate with Flow
  • Fix Flow types, if required
  • Integrate with tests
  • Fix tests
  • Silence console.warn in tests with React repo's toWarnDev utility
  • Add FB copyright header
  • Fix CI (we'll only be able test this in the PR to upstream)

Test Plan

  • yarn lint
  • yarn test
  • yarn flow dom
  • In react-scheduling-profiler package:

Brian Vaughn and others added 30 commits January 6, 2020 15:02
Disable parcel caching to fix tooltips
Enable Flow in VS Code by adding flow-bin, .flowconfig and VS code settings
Based on CRA's setup.
* Move constants to constants.js

* Reorg, typo fixes

* Move more helper funcs to canvasUtils

* Move canvas code to canvas

* Move helper functions into utils

* Run prettier, fix CLI script command

* remove unused imports in app.js, rename utils.js

* Update renderCanvas.js

* prettier CLI fix, move constants to canvas
* Upgrade Prettier

* Copy React's Prettier config

* Customize prettier config to allow CSS/JSON prettifying and ignore folders

* yarn prettier

* Downgrade to Prettier 1.19.1 and run prettier
* Copy React's ESLint config

* Add ESLint etc deps and lint script

Copied from React, but we also upgrade all of them except
eslint-config-fbjs.

* Delete all irrelevant ESLint rules

* Run yarn lint --fix

* Fix lint

* Replace single quotes in lint stript with double quotes

* Add newline at end of .eslintignore
* Add GitHub Actions workflow

Adds CI workflow to run `yarn lint`, `yarn test`, and `yarn build`. `yarn flow` excluded for now as we still have many typecheck failures.

Based on:
- Default Node.js workflow
- https://github.com/actions/cache/blob/master/examples.md#node---yarn

* Prettify node.js.yml

* Configure test script to pass with no tests

Tests are currently failing as there are no tests in the codebase. This
commit adds `--passWithNoTests` to make Jest not error.

This commit should be reverted once there are tests in our codebase.

* Revert "Configure test script to pass with no tests"

This reverts commit bd57b9ea82328fb3765b91b7847eb99f51b7aae4.

* Fix lint in new files on master
* Unexport unnecessary exported vars in src/canvas

* Remove unused App.css classes

* Extract CanvasPage from App.js and clean up now-non-nullable types

* Wrap App in React.StrictMode

* Extract automatic ImportPage from App.js

* Wrap App updates in batchedUpdates
`preprocessDataV2` previously took the `ts` value of the first timeline
event, following `preprocessData`. However, this is problematic with
Chrome performance data, as Chrome sticks a bunch of metadata events
(i.e. `ph === 'M'`) with `ts === 0`. This caused the computed React
events and measures to have enormous `timestamp` values, since they were
now offset from 0 instead of being offset from the first event.

This commit fixes this issue by taking the `ts` value of the first event
with a non-zero and non-undefined `ts`.

This fix was implemented with reference to the trace event doc:
https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview

1. V2 measures now appear correctly in WIP (not pushed) canvas with V2
   data.
1. CI. Tests still passing.
Fix preprocessDataV2 to prevent enormous React timestamps
@taneliang taneliang changed the title Checkin prototype with small example profile JSON Import React Concurrent Mode Profiler Aug 18, 2020
@taneliang taneliang marked this pull request as ready for review August 18, 2020 04:43
Copy link
Member

@kartikcho kartikcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the sample profile in? It makes sense for dev purposes but they're pretty big in size, almost around the size of the whole package. Not sure how the React team would feel about it.

@taneliang
Copy link
Member Author

taneliang commented Aug 18, 2020

Good question, let's ask the React team on the final PR. I think we'll want to keep it around as the demo profile for MLH-Fellowship/scheduling-profiler-prototype#82. It's lazily loaded anyway so at least it won't bloat the main bundle

@taneliang taneliang force-pushed the scheduling-profiler-import branch from 892711a to 42a59e6 Compare August 19, 2020 05:55
@taneliang
Copy link
Member Author

Merged upstream: facebook#19634

@taneliang taneliang closed this Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import this project into React repo packages
3 participants