Closed kylebjordahl closed 5 months ago
After more tinkering with my perf-test
plugin, I have discovered that if I build the plugin and place it within the node_modules
dir to approximate installing a 3rd party plugin, it loads remarkably fast. (Logs below)
It seems there is something wrong with loading local TS plugins
workspace git:(kb/RN-769-upgrade-to-nx-19) time NX_PERF_LOGGING=true NX_DAEMON=false NX_CACHE_PROJECT_GRAPH=false NX_ISOLATE_PLUGINS=true pnpm nx graph --file=tmp_file3.json --verbose
Time for 'loading dotenv files' 1.1174579999999992
Time for 'workspace context init' 3.954625000000007
Time for 'Load Nx Plugin: /home/vscode/workspace/node_modules/.pnpm/nx@19.1.1_@swc-node+register@1.9.1_@swc+core@1.5.24/node_modules/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json' 0.44529099999999744
Time for 'Load Nx Plugin: @nx/eslint/plugin' 2.4542920000000095
Time for 'Load Nx Plugin: /home/vscode/workspace/node_modules/.pnpm/nx@19.1.1_@swc-node+register@1.9.1_@swc+core@1.5.24/node_modules/nx/src/plugins/target-defaults/target-defaults-plugin' 2.9343749999999886
Time for 'Load Nx Plugin: /home/vscode/workspace/node_modules/.pnpm/nx@19.1.1_@swc-node+register@1.9.1_@swc+core@1.5.24/node_modules/nx/src/plugins/js' 7.256458000000009
Time for 'Load Nx Plugin: /home/vscode/workspace/node_modules/.pnpm/nx@19.1.1_@swc-node+register@1.9.1_@swc+core@1.5.24/node_modules/nx/src/plugins/package-json-workspaces' 0.47204099999999016
Time for 'Load Nx Plugin: @nx/vite/plugin' 254.830208
Time for 'Load Nx Plugin: @rh-plugins/perf-test' 51.146124999999984
Time for 'Load Nx Plugin: /home/vscode/workspace/node_modules/.pnpm/nx@19.1.1_@swc-node+register@1.9.1_@swc+core@1.5.24/node_modules/nx/src/plugins/project-json/build-nodes/project-json' 0.37720899999999347
Time for 'Load Nx Plugin: @nx/storybook/plugin' 213.89875
Time for 'Load Nx Plugin: @nx/remix/plugin' 76.697
Time for 'Load Nx Plugin: @nxlv/python' 194.76016700000002
Time for '@nx/remix/plugin:createNodes' 0.046625000000062755
Time for 'nx/js/dependencies-and-lockfile:createNodes' 40.426874999999995
Time for '@rh-plugins/perf-test:createNodes' 139.61029199999996
Time for 'nx/core/package-json:createNodes' 223.16429199999993
Time for 'nx/core/package-json-workspaces:createNodes' 177.91375000000005
Time for 'nx/core/project-json:createNodes' 176.405125
Time for '@nx/storybook/plugin:createNodes' 321.95854199999997
Time for 'workspace context init' 5.202041000000008
Time for '@nx/vite/plugin:createNodes' 328.05991700000004
Time for 'workspace context init' 10.170041999999967
Time for 'nx/core/target-defaults:createNodes' 341.43791699999997
Time for '@nx/eslint/plugin:createNodes' 1881.7331680000002
Time for 'workspace context init' 5.841625000000022
Time for 'build-project-configs' 1942.886418
Time for 'createNodes:merge' 7.167707999999948
Time for 'native-file-deps' 0.1515409999997246
Time for 'get-workspace-files' 2.2273339999997006
Time for 'get-all-workspace-files' 10.753375000000233
Time for '@nx/storybook/plugin:createDependencies' 98.18079200000011
Time for '@nx/remix/plugin:createDependencies' 84.69016600000032
Time for '@nx/vite/plugin:createDependencies' 62.47445800000014
Time for '@nxlv/python:createDependencies' 239.52779200000032
Time for 'build typescript dependencies' 549.6482080000001
NX JSON output created in /home/vscode/workspace
/home/vscode/workspace/tmp_file3.json
NX_PERF_LOGGING=true NX_DAEMON=false NX_CACHE_PROJECT_GRAPH=false =true pnpm 0.66s user 0.31s system 26% cpu 3.720 total
Narrowing it down even further, I added some performance marks in my local nx install, specifically in node_modules/nx/src/plugins/js/utils/typescript.js:readTsConfig
and it looks as though this is where all the time is getting spent on plugin loading, specifically in tsModule.parseJsonConfigFileContent
Time for 'Load Nx Plugin: @rh-plugins/ruff' 62171.26652999999
Time for 'readTsConfig - readConfigFile total' 5.7970000000000255
Time for 'readTsConfig - Total' 61845.963154
So, going out on a wild limb, I tried making a few under-the-hood tweaks and managed to get some pretty significant speed improvements by avoiding the call to tsModule.parseJsonConfigFileContent
altogether; from what I can tell, registerPluginTSTranspiler
doesn't actually need most of the output generated by parseJsonConfigFileContent
, it really just wants the contents of the tsconfig.json
file.
I'll provide a PR that represents what I've found, and hopefully this can get sorted out quickly
After investigating the performance of parseJsonConfigFileContent
(mostly by running tsc --showConfig
) I finally diagnosed this as an issue in our tsconfig.base.json
excludes.
I ended up adding some extra excludes, it might be ideal to include some of these in the default which is generated for new workspaces:
"exclude": ["**/node_modules", "**/.*/", "tmp", "**/cdk.out", "dist"]
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
Running any command which utilizes the project graph results in very slow CLI results.
nx graph
currently takes over 1 minute to complete; the same happens when running basic project targets likelint
andtest
. Runningtime nx report
for this issue took over 9 minutesIt appears that our custom plugins are taking orders of magnitude longer to load than 1st and 3rd party Nx plugins; while I cannot share the source code as this is a private repo, I can say that I have tried removing our local plugins from the
nx.json
and this restores the CLI to more acceptable speeds.I have also tried creating a wholly new plugin with the following
createNodes
implementation, and it still takes an unbelievably long time to load the plugin (it has zero dependencies and only the oneindex.ts
file).perf test plugin
Logs
Expected Behavior
Nx CLI should perform commands in a timely fashion that does not dramatically hinder developer productivity.
GitHub Repo
No response
Steps to Reproduce
I've tried to reproduce in the nx-examples lib, and while I can see a slight change in CLI time when I have a custom plugin, it's not nearly as dramatic as we are seeing in our repo. It could be because of the difference in scale (we have nearly 100 projects)
Nx Report
Failure Logs
Package Manager Version
pnpm@8.15.7
Operating System
Additional Information
Running in a devcontainer on MacOS 14.3.1 (M1 chip), devcontainer OS is Ubuntu 22.04
This issue was opened after working with Miro from Nx Cloud Support via email, on their recommendation