如何调试FlowType运行性能极度缓慢的问题
FlowType运行极其缓慢,如何查看保存/输入后生成的依赖树?
工作中需要使用FlowType,但它运行速度极其缓慢,已尝试删除flow-typed定义、消除循环依赖等多种优化方案,问题仍未解决。目前没有更多排查思路,也不清楚该如何调试该问题,想要了解有没有方法可以查看每次保存/敲击键盘后生成的依赖树。
编辑1
以下是当前使用的.flowconfig配置:
[ignore] .*/node_modules/react-native-keyboard-aware-scroll-view/.* .*/node_modules/react-native-fbsdk/.* .*/node_modules/@react-native-community/picker.* .*/node_modules/@react-native-community/slider.* ; remove when flow is updated. Currently leads to "Cannot assign rest to restState because rest [1] is incompatible with State [2]." .*/node_modules/redux-persist/lib/persistReducer.js.flow .*/node_modules/recompose/dist/Recompose.cjs.js.flow ; Ignores sub apps .*/firebase/** .*/webapp/** .*/node_modules/react-native-androw/src.* ; Migration to RN 0,64 causes some random errors .*/node_modules/react-navigation-redux-helpers .*/node_modules/react-navigation-redux-helpers .*/node_modules/react-native-calendars ; .*/node_modules/react-native/Libraries/Interaction ; .*/node_modules/react-native/Libraries/Logbox/Data ; We fork some components by platform .*/*[.]android.js ; Ignore "BUCK" generated dirs <PROJECT_ROOT>/\.buckd/ ; Ignore polyfills node_modules/react-native/Libraries/polyfills/.* ; Flow doesn't support platforms .*/Libraries/Utilities/LoadingView.js [untyped] .*/node_modules/@react-native-community/cli/.*/.* .*/node_modules/react-native-confetti-cannon/.* .*/node_modules/react-native-linear-gradient/.* [libs] node_modules/react-native/interface.js node_modules/react-native/flow/ flow/libs [options] emoji=true server.max_workers=1 sharedmemory.hash_table_pow=22 esproposal.optional_chaining=enable esproposal.nullish_coalescing=enable ; RN 0.64 turns this on, our codebase explodes ; exact_by_default=true module.file_ext=.js module.file_ext=.json module.file_ext=.ios.js module.system.node.allow_root_relative=true munge_underscores=true module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1' 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\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub' module.name_mapper.extension='svg' -> '<PROJECT_ROOT>/flow/SVGFlowStub.js' suppress_type=$FlowIssue suppress_type=$FlowFixMe suppress_type=$FlowFixMeProps suppress_type=$FlowFixMeState ; Types first is the architecture that forces very very strict rules (always export typed results) ; In order to increase the performance of flow (it is painfully slow) ; However our codebase is in no way shape or form ready for this (it throws around 567 type errors) types_first=false [lints] sketchy-null-number=warn sketchy-null-mixed=warn sketchy-number=warn untyped-type-import=warn nonstrict-import=warn deprecated-type=warn unsafe-getters-setters=warn unnecessary-invariant=warn signature-verification-failure=warn [strict] deprecated-type nonstrict-import sketchy-null unclear-type unsafe-getters-setters untyped-import untyped-type-import [version] ^0.137.0
还尝试更换了其他Flow插件,原本怀疑问题和插件向Flow服务器发送过多请求有关,更换后性能仅有小幅提升,没有明显改善。
编辑2
又尝试了多种方案,包括删除为recompose编写的大量类型定义,将大量类型提取到libDef中,依然没有效果。判断问题出在项目架构上:所有类型都声明在types/index.js文件中,每次使用都需要手动导入,比如import type { UUID } from 'src/types',正因为所有类型都集中声明在这里,所以每次修改保存后Flow都需要检查400+文件,依赖树本身没有问题。
编辑3
最终解析了整个应用的依赖树来排查问题,得出的结论是Flow本身没有问题,问题出在导入逻辑上,主要是Redux和Sagas的导入逻辑导致只要导入一个内容就会触发整个应用的重新检查。
内容的提问来源于stack exchange,提问作者Oscar Franco
相关产品推荐
相关产品推荐

