Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bazel): improve performance of tsHost.writeFile() #34331

Closed
wants to merge 1 commit into from

Conversation

@kyliau
Copy link
Member

kyliau commented Dec 10, 2019

Removing from an array incurs O(n^2) cost, and could be mitigated with the use of a Set instead.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@kyliau kyliau requested a review from gregmagolan Dec 10, 2019
@kyliau kyliau requested a review from angular/tools-bazel as a code owner Dec 10, 2019
@ngbot ngbot bot added this to the needsTriage milestone Dec 10, 2019
@googlebot googlebot added the cla: yes label Dec 10, 2019
@kyliau kyliau requested a review from dgp1130 Dec 10, 2019
if (expectedIdx >= 0) {
writtenExpectedOuts.splice(expectedIdx, 1);
if (writtenExpectedOuts.has(relative)) {
writtenExpectedOuts.delete(relative);

This comment has been minimized.

Copy link
@dgp1130

dgp1130 Dec 10, 2019

Contributor

If a file is written multiple times, wouldn't this be a problem? Considering this logic was already the case it might not be a problem, but we probably shouldn't assume that the compiler will only write out to a file once.

Also the name writtenExpectedOuts is a little off, since they haven't been written yet on line 202. I'd recommend having a const expectedOuts set on line 202 with a separate writtenExpectedOuts set which gets added on each tsHost.writeFile, then take the set difference between the two at the end. I think that's a little clearer in intent though it might be a little slower, I don't think it would have significant performance implications (tsHost.writeFile would be effectively the same and that's the bottleneck).

This comment has been minimized.

Copy link
@kyliau

kyliau Dec 10, 2019

Author Member

If a file is written multiple times

I don't think we'll ever hit this case. If we do, it might be a compiler bug / setup error.

I agree having two sets would make the intent clearer, but it also requires iterating through one of the sets at the end to figure out the set difference.
I've instead renamed writtenExpectedOuts to expectedOutsSet to make it clear that possibly not all files in the set are written out and I also added a comment.

Removing from an array incurs O(n^2) cost, and could be mitigated with the use of a Set instead.
@kyliau kyliau force-pushed the kyliau:ngc-wrapped branch from 48c19d9 to d61b984 Dec 10, 2019
@kyliau kyliau removed the request for review from gregmagolan Dec 11, 2019
AndrewKushnir added a commit that referenced this pull request Dec 11, 2019
Removing from an array incurs O(n^2) cost, and could be mitigated with the use of a Set instead.

PR Close #34331
petebacondarwin added a commit to petebacondarwin/angular that referenced this pull request Dec 11, 2019
Removing from an array incurs O(n^2) cost, and could be mitigated with the use of a Set instead.

PR Close angular#34331
@kyliau kyliau deleted the kyliau:ngc-wrapped branch Dec 17, 2019
@angular-automatic-lock-bot

This comment has been minimized.

Copy link

angular-automatic-lock-bot bot commented Jan 17, 2020

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 Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.