flow / flow-bin

Binary wrapper for Flow - A static type checker for JavaScript
https://flow.org
Other
535 stars 47 forks source link

Flow constant 100% CPU core usage #152

Closed mjmasn closed 2 years ago

mjmasn commented 5 years ago

I'm running flow-ide (in LSP mode) in Atom text editor with Flow 0.95.1, although this has been a problem across a few versions.

As soon as I open our React Native project in Atom, flow takes a full CPU core forever. Make any changes and it can take 3~5 minutes for the errors to update in Atom.

What's the best way to debug this? Ignoring node_modules in .flowconfig works, so I'm guessing there's a file that's confusing flow in there somewhere, but then we get Cannot resolve module 'react-native' etc. errors.

Is there a way to see timings for each file or something along those lines?

As I've typed out this issue CPU usage has remained at 100% of a core, with memory usage in a loop of roughly 400MB -> 800MB -> 1200MB -> 400MB etc. on a 2s interval in the system monitor.

Output of react-native info:

info 
  React Native Environment Info:
    System:
      OS: Linux 4.15 Ubuntu 16.04.6 LTS (Xenial Xerus)
      CPU: (8) x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
      Memory: 1.66 GB / 15.54 GB
      Shell: 4.3.48 - /bin/bash
    Binaries:
      Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
      Yarn: 1.15.2 - /usr/bin/yarn
      npm: 5.6.0 - ~/.nvm/versions/node/v8.11.3/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      Android SDK:
        API Levels: 24, 26, 27, 28
        Build Tools: 23.0.1, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.3, 28.0.2, 28.0.3
        System Images: android-24 | Google APIs ARM 64 v8a, android-24 | Google APIs Intel x86 Atom, android-24 | Google APIs Intel x86 Atom_64, android-24 | Google Play Intel x86 Atom, android-25 | Google Play Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-Q | Google Play Intel x86 Atom_64
    IDEs:
      Android Studio: 3.1 AI-173.4907809
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: ^0.58.6 => 0.58.6 
    npmGlobalPackages:
      create-react-native-app: 2.0.2
      react-native-cli: 2.0.1
      react-native-create-library: 3.1.2
      react-native-git-upgrade: 0.2.7

Contents of .flowconfig (I think this is the default one from RN, plus the strict mode config)

[ignore]
; We fork some components by platform
.*/*[.]android.js

; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/

; Ignore unexpected extra "@providesModule"
.*/node_modules/.*/node_modules/fbjs/.*

; Ignore duplicate module providers
; For RN Apps installed via npm, "Libraries" folder is inside
; "node_modules/react-native" but in the source repo it is in the root
.*/Libraries/react-native/React.js

; Ignore polyfills
.*/Libraries/polyfills/.*

; Ignore metro
.*/node_modules/metro/.*

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/
node_modules/react-native/flow-github/

[options]
emoji=true

module.system=haste
module.system.haste.use_name_reducers=true
# get basename
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
# strip .js or .js.flow suffix
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
# strip .ios suffix
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
module.system.haste.paths.blacklist=.*/__tests__/.*
module.system.haste.paths.blacklist=.*/__mocks__/.*
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*

munge_underscores=true

module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'

module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.file_ext=.native.js

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[lints]
sketchy-null=warn
sketchy-null-bool=off

[strict]
# recommended
nonstrict-import
unclear-type
unsafe-getters-setters
untyped-import
untyped-type-import
# other
# sketchy-null
sketchy-number
unnecessary-optional-chain
unnecessary-invariant
deprecated-utility
mjmasn commented 5 years ago

OK so I ended up just adding a list of all 900 node_modules directories to [ignore] then removed 50% at a time. Narrowed it down to https://github.com/oblador/react-native-vector-icons.

It's not clear to me that it would be their fault though, unless they're doing something very bad in their flow defs, I guess the issue is probably still in flow-bin :thinking:

alpha0010 commented 5 years ago

The type definitions contain enums for the available icon names, allowing flow to validate the icon you are requesting exists in the requested set. For some sets (such as font awesome), these enums are can be lengthy. I wonder if the flow people changed some internals such that they now have a hard time handling such.

mjmasn commented 5 years ago

@alpha0010 thanks for the reply. Sounds like that might be the case, we're using material community icons as well as a custom icon font so about 3800 possible icons across the two components. Not sure if the types for the unused icon sets are still processed as well?

gyto23 commented 4 years ago

Have same issue on the v0.121.0 Macbook Pro, downgraded to v0.113.0 at least one of the stable that doesn't spin my fans

mroch commented 2 years ago

Closing out old issues. This repository is just packaging prebuilt binaries. Please report issues with Flow itself on facebook/flow