I have a rather large React app where we have rather successfully typed practically all of it.
Things like the root-level state, etc., all are going in a ui/types.js for easy import. Consumers can do things like import type {AppState, Locale} from 'ui/types' and so on.
We also include the root-level Flux instance and Stores in this file, which requires importing each individual store to properly type (as each Store has its own methods).
This is causing slow merging inference steps, as changes to most files require re-merging the types of all 313 files:
[2016-11-28 14:27:38] Server is READY
[2016-11-28 14:27:38] Took 14.510482 seconds to initialize.
recheck 1 modified, 0 deleted files
modified files:
1/1: /proj/frontend/ui/stores/mixins/RestBindingMixin.js
[2016-11-28 14:29:09] Parsing
[2016-11-28 14:29:09] Running local inference
[2016-11-28 14:29:09] remerge 313 dependent files:
[2016-11-28 14:29:09] 1/313: /proj/frontend/index.js
....
[2016-11-28 14:29:09] 313/313: /proj/frontend/webpack/storybook/config.js
[2016-11-28 14:29:09] Merge prep
[2016-11-28 14:29:09] Re-resolving directly dependent files
[2016-11-28 14:29:09] Calculating dependencies
[2016-11-28 14:29:09] Merging
[2016-11-28 14:29:16] Done
[2016-11-28 14:29:16] Sharedmem GC: 183786304 bytes before; 121203584 bytes after; in 0.178280 seconds
[2016-11-28 14:29:31] Status: OK
This means that even 'hot' changes take 7 seconds, pegging all 8 cores.
I have noticed that interim check-contents runs (run by the Sublime Text 3 FlowIDE plugin) are very fast, as check-contents does not cause this remerge.
Is there a preferred way to handle issues like this? Consolidating types in this way has proven very useful; we use helpers like datumKey: $PropertyType<AppState, 'datumKey'> to easily capture the dependencies of components even though the root state may change in some way.
Hey @STRML, I'd love to get an update on whether this is still super slow, or if newer versions of Flow have improved things.
Without benchmarking, I can't really know what's slow. But I might speculate that if you're using type inference on lots of React components, that has been slow in the past. I think the changes to the Component type in Flow v0.53, which require you to be more explicit, but also remove some pathological cases with inference, might help here.
Thanks for the follow-up.
I haven't yet upgraded to v0.53, but when I do I'll keep an eye out for this and update the issue.
I appreciate your time!
This is still very slow for us even with v0.70. Any pointers on speeding up merging?
I would recommend using flow cycle and inspecting the graph. This can help you ensure you do not have cyclic imports and cyclic structures.