Skip to content

perf(bazel): use allowedInputs to avoid fs.stat#46069

Closed
frigus02 wants to merge 1 commit intoangular:mainfrom
frigus02:optimize-fileexists
Closed

perf(bazel): use allowedInputs to avoid fs.stat#46069
frigus02 wants to merge 1 commit intoangular:mainfrom
frigus02:optimize-fileexists

Conversation

@frigus02
Copy link
Contributor

PR Checklist

Regarding tests: Do you have a way to test for file system calls during compilation?

PR Type

  • Build related changes

What is the current behavior?

ngc-wrapped calls TypeScript's fileExists function during module resolution, which calls fs.statSync.

File system calls can be quite slow depending on the file system. In google3 I saw a 38 seconds compilation, which spent 6 seconds just doing fs.stat calls during module resolution.

What is the new behavior?

Call tsc_wrapped's fileExists function instead of TypeScript's.

tsc_wrapped (used internally by ngc-wrapped) has an optimization under bazel to avoid file system calls where possible. It takes advantage bazelOpts.allowedInputs, which contains a list of all files available for compilation.

The fs.stat calls mentioned for the slow google3 target are entirely gone after with this change.

Does this PR introduce a breaking change?

  • No

Call tsc_wrapped's fileExists function instead of TypeScript's.

tsc_wrapped (used internally by ngc-wrapped) has an optimization under
bazel to avoid file system calls where possible. It takes advantage
bazelOpts.allowedInputs, which contains a list of all files available
for compilation.

File system calls can be quite slow depending on the file system. In
google3 I saw a 38 seconds compilation, which spent 6 seconds just doing
fs.stat calls during module resolution. Those fs.stat calls are entirely
gone after with this change.
@pullapprove pullapprove bot requested a review from devversion May 20, 2022 09:01
@frigus02
Copy link
Contributor Author

frigus02 commented May 20, 2022

Here are screenshots of a CPU profile before and after the change:

Before After
biggest contributor to execution time is statSync with ~6s, after that is openSync with 800ms statSync is gone. biggest contributors are now scan with 900ms and openSync with 800ms

More details are in an internal ticket: http://b/232199273#comment2

@devversion devversion added action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit target: rc This PR is targeted for the next release-candidate area: bazel Issues related to the published `@angular/bazel` build rules labels May 20, 2022
@ngbot ngbot bot added this to the Backlog milestone May 20, 2022
@devversion
Copy link
Member

devversion commented May 20, 2022

Presubmit: cl/449952536 (we want to wait for a TGP)

@devversion devversion added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit action: merge The PR is ready for merge by the caretaker labels May 20, 2022
@alxhub
Copy link
Member

alxhub commented May 24, 2022

This PR was merged into the repository by commit 7efa09b.

@alxhub alxhub closed this in 7efa09b May 24, 2022
alxhub pushed a commit that referenced this pull request May 24, 2022
Call tsc_wrapped's fileExists function instead of TypeScript's.

tsc_wrapped (used internally by ngc-wrapped) has an optimization under
bazel to avoid file system calls where possible. It takes advantage
bazelOpts.allowedInputs, which contains a list of all files available
for compilation.

File system calls can be quite slow depending on the file system. In
google3 I saw a 38 seconds compilation, which spent 6 seconds just doing
fs.stat calls during module resolution. Those fs.stat calls are entirely
gone after with this change.

PR Close #46069
@frigus02 frigus02 deleted the optimize-fileexists branch May 25, 2022 12:03
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: bazel Issues related to the published `@angular/bazel` build rules target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants