Description
Enable parallel compilation via Node.js Child Processes. A call to Compiler.compileAsync() will child_process.spawn() a separate process for each source module indicated during Compiler construction, and then it will wait to return until all compilations have completed.
Testing instructions
Types of changes
- New feature (non-breaking change which adds functionality)
Checklist:
- [x] Prefix the title of this PR with
[WIP]if it is a work in progress. - [x] Prefix the title of this PR with bracketed package name(s) corresponding to the changed package(s). For example:
[sol-cov] Fixed bug. - [x] Refactor to move solcjs invocation to behind a command-line interface, so that it can be spawned as a parallel process via Node's Child Process API.
- [x] Change
Compilerto actually spawn multiple parallel processes, and to wait for them all to complete before finishing a call tocompileAync(). - [x] Fix bug with truncated JSON stdout from command-line utility. Check.
- [x] Consider other IPC methods, besides parsing stdin/stdout to and from JSON. Some may be more performant or appropriate for our use case, and perhaps we could simplify our code. For example, we may be able to eliminate much of our parsing and glue code by using Node's plain-old-js-object-driven message events API, or maybe there's an RPC technique that will allow the
Resolverto stay in the parent process. Check. - [x] Allay race condition when downloading
solcjsexecutable. Two parallel processes may try to download it to the same location at the same time. Perhaps movecompilerBinFilenameinitialization block fromcli_resolver_solc.tsto just before its invocation in the Compiler class, so that downloading the executable happens in the single-threaded parent process rather than in the parallel child processes. - [x] Implement a configuration/option for degree of parallelism. As it stands now, if your project has 50 contracts, then you'll get 50 parallel processes. Perhaps a command line flag, akin to GNU Make's -j. Check.
- [ ] Clean up
yargsusage in cli_resolver_solc.ts, marking things required, etc. - [ ] Add tests to cover my changes, or decided that tests would be too impractical.
- [ ] Updat documentation as needed.
- [ ] Add new entries to the relevant CHANGELOG.jsons.
该提问来源于开源项目:0xProject/0x-monorepo