[S] Change in dart/sdk[main]: Optimize LibraryContext.remove.

1 view
Skip to first unread message

Konstantin Shcheglov (Gerrit)

unread,
Mar 11, 2026, 12:04:07 PMMar 11
to Morgan :), Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Morgan :)

Konstantin Shcheglov added 1 comment

File pkg/analyzer/lib/src/dart/analysis/library_context.dart
Line 157, Patchset 4 (Latest): if (removed.isEmpty) return;
Konstantin Shcheglov . unresolved

This part was discussed and makes sense to me.

The rest, I'm not sure.
I don't like using `internal_libraryCycle`, this breaks layering.
I don't like special-casing was / was-not cycle created.
If there is no cycle, we could not have added it to loaded bundles.

Open in Gerrit

Related details

Attention is currently required from:
  • Morgan :)
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I98546cb34ebd6b8c16ae4a902e5b0b2834a1f4e8
Gerrit-Change-Number: 486981
Gerrit-PatchSet: 4
Gerrit-Owner: Morgan :) <david...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Morgan :) <david...@google.com>
Gerrit-Attention: Morgan :) <david...@google.com>
Gerrit-Comment-Date: Wed, 11 Mar 2026 16:04:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Morgan :) (Gerrit)

unread,
Mar 11, 2026, 12:15:16 PMMar 11
to Konstantin Shcheglov, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Konstantin Shcheglov

Morgan :) added 1 comment

File pkg/analyzer/lib/src/dart/analysis/library_context.dart
Line 157, Patchset 4 (Latest): if (removed.isEmpty) return;
Konstantin Shcheglov . unresolved

This part was discussed and makes sense to me.

The rest, I'm not sure.
I don't like using `internal_libraryCycle`, this breaks layering.
I don't like special-casing was / was-not cycle created.
If there is no cycle, we could not have added it to loaded bundles.

Morgan :)

I added the special case for the null cycle to make the unit test pass; it's possible that the correct fix for the unit test failures was to update the unit test state.

https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8687635310137556417/+/u/test_results/new_test_failures__logs_

On large codebases (5000 files) it looks like the analyzer (via build_runner) is spending almost as much time calling "remove" as doing analysis. So we can definitely benefit from some optimization here :) I posted a few screenshots on the linked bug, obviously I can share detail+repro.

Thanks.

Open in Gerrit

Related details

Attention is currently required from:
  • Konstantin Shcheglov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I98546cb34ebd6b8c16ae4a902e5b0b2834a1f4e8
Gerrit-Change-Number: 486981
Gerrit-PatchSet: 4
Gerrit-Owner: Morgan :) <david...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Morgan :) <david...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Comment-Date: Wed, 11 Mar 2026 16:15:11 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Konstantin Shcheglov <sche...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Konstantin Shcheglov (Gerrit)

unread,
Mar 11, 2026, 12:19:28 PMMar 11
to Morgan :), Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Morgan :)

Konstantin Shcheglov added 1 comment

File pkg/analyzer/lib/src/dart/analysis/library_context.dart
Line 157, Patchset 4 (Latest): if (removed.isEmpty) return;
Konstantin Shcheglov . unresolved

This part was discussed and makes sense to me.

The rest, I'm not sure.
I don't like using `internal_libraryCycle`, this breaks layering.
I don't like special-casing was / was-not cycle created.
If there is no cycle, we could not have added it to loaded bundles.

Morgan :)

I added the special case for the null cycle to make the unit test pass; it's possible that the correct fix for the unit test failures was to update the unit test state.

https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8687635310137556417/+/u/test_results/new_test_failures__logs_

On large codebases (5000 files) it looks like the analyzer (via build_runner) is spending almost as much time calling "remove" as doing analysis. So we can definitely benefit from some optimization here :) I posted a few screenshots on the linked bug, obviously I can share detail+repro.

Thanks.

Konstantin Shcheglov

There are two main changes: `if removed.isEmpty` and the rest.
Do we get not enough optimized by `isEmpty` check?

Open in Gerrit

Related details

Attention is currently required from:
  • Morgan :)
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I98546cb34ebd6b8c16ae4a902e5b0b2834a1f4e8
Gerrit-Change-Number: 486981
Gerrit-PatchSet: 4
Gerrit-Owner: Morgan :) <david...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Morgan :) <david...@google.com>
Gerrit-Attention: Morgan :) <david...@google.com>
Gerrit-Comment-Date: Wed, 11 Mar 2026 16:19:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Morgan :) <david...@google.com>
Comment-In-Reply-To: Konstantin Shcheglov <sche...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Morgan :) (Gerrit)

unread,
Mar 11, 2026, 12:23:06 PMMar 11
to Konstantin Shcheglov, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Konstantin Shcheglov

Morgan :) added 1 comment

File pkg/analyzer/lib/src/dart/analysis/library_context.dart
Line 157, Patchset 4 (Latest): if (removed.isEmpty) return;
Konstantin Shcheglov . unresolved

This part was discussed and makes sense to me.

The rest, I'm not sure.
I don't like using `internal_libraryCycle`, this breaks layering.
I don't like special-casing was / was-not cycle created.
If there is no cycle, we could not have added it to loaded bundles.

Morgan :)

I added the special case for the null cycle to make the unit test pass; it's possible that the correct fix for the unit test failures was to update the unit test state.

https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8687635310137556417/+/u/test_results/new_test_failures__logs_

On large codebases (5000 files) it looks like the analyzer (via build_runner) is spending almost as much time calling "remove" as doing analysis. So we can definitely benefit from some optimization here :) I posted a few screenshots on the linked bug, obviously I can share detail+repro.

Thanks.

Konstantin Shcheglov

There are two main changes: `if removed.isEmpty` and the rest.
Do we get not enough optimized by `isEmpty` check?

Morgan :)

No, they help with different cases:

 - isEmpty is not relevant to build_runner, it helps if you have many drivers
- the more complex optimization helps any file change based on codebase size, this is the one that speeds up build_runner

I can split them up if you like :)

Open in Gerrit

Related details

Attention is currently required from:
  • Konstantin Shcheglov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I98546cb34ebd6b8c16ae4a902e5b0b2834a1f4e8
Gerrit-Change-Number: 486981
Gerrit-PatchSet: 4
Gerrit-Owner: Morgan :) <david...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Morgan :) <david...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Comment-Date: Wed, 11 Mar 2026 16:23:01 +0000
satisfied_requirement
unsatisfied_requirement
open
diffy

Konstantin Shcheglov (Gerrit)

unread,
Mar 11, 2026, 12:30:13 PMMar 11
to Morgan :), Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Morgan :)

Konstantin Shcheglov added 1 comment

File pkg/analyzer/lib/src/dart/analysis/library_context.dart
Line 157, Patchset 4 (Latest): if (removed.isEmpty) return;
Konstantin Shcheglov . unresolved

This part was discussed and makes sense to me.

The rest, I'm not sure.
I don't like using `internal_libraryCycle`, this breaks layering.
I don't like special-casing was / was-not cycle created.
If there is no cycle, we could not have added it to loaded bundles.

Morgan :)

I added the special case for the null cycle to make the unit test pass; it's possible that the correct fix for the unit test failures was to update the unit test state.

https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8687635310137556417/+/u/test_results/new_test_failures__logs_

On large codebases (5000 files) it looks like the analyzer (via build_runner) is spending almost as much time calling "remove" as doing analysis. So we can definitely benefit from some optimization here :) I posted a few screenshots on the linked bug, obviously I can share detail+repro.

Thanks.

Konstantin Shcheglov

There are two main changes: `if removed.isEmpty` and the rest.
Do we get not enough optimized by `isEmpty` check?

Morgan :)

No, they help with different cases:

 - isEmpty is not relevant to build_runner, it helps if you have many drivers
- the more complex optimization helps any file change based on codebase size, this is the one that speeds up build_runner

I can split them up if you like :)

Konstantin Shcheglov

Yes, I think splitting and having separate issue for discussing the second portion would be useful.

Open in Gerrit

Related details

Attention is currently required from:
  • Morgan :)
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I98546cb34ebd6b8c16ae4a902e5b0b2834a1f4e8
Gerrit-Change-Number: 486981
Gerrit-PatchSet: 4
Gerrit-Owner: Morgan :) <david...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Morgan :) <david...@google.com>
Gerrit-Attention: Morgan :) <david...@google.com>
Gerrit-Comment-Date: Wed, 11 Mar 2026 16:30:09 +0000
satisfied_requirement
unsatisfied_requirement
open
diffy

Morgan :) (Gerrit)

unread,
Mar 11, 2026, 1:11:49 PMMar 11
to Konstantin Shcheglov, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Konstantin Shcheglov

Morgan :) voted and added 1 comment

Votes added by Morgan :)

Auto-Submit+1

1 comment

File pkg/analyzer/lib/src/dart/analysis/library_context.dart
Line 157, Patchset 4: if (removed.isEmpty) return;
Konstantin Shcheglov . unresolved

This part was discussed and makes sense to me.

The rest, I'm not sure.
I don't like using `internal_libraryCycle`, this breaks layering.
I don't like special-casing was / was-not cycle created.
If there is no cycle, we could not have added it to loaded bundles.

Morgan :)

I added the special case for the null cycle to make the unit test pass; it's possible that the correct fix for the unit test failures was to update the unit test state.

https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8687635310137556417/+/u/test_results/new_test_failures__logs_

On large codebases (5000 files) it looks like the analyzer (via build_runner) is spending almost as much time calling "remove" as doing analysis. So we can definitely benefit from some optimization here :) I posted a few screenshots on the linked bug, obviously I can share detail+repro.

Thanks.

Konstantin Shcheglov

There are two main changes: `if removed.isEmpty` and the rest.
Do we get not enough optimized by `isEmpty` check?

Morgan :)

No, they help with different cases:

 - isEmpty is not relevant to build_runner, it helps if you have many drivers
- the more complex optimization helps any file change based on codebase size, this is the one that speeds up build_runner

I can split them up if you like :)

Konstantin Shcheglov

Yes, I think splitting and having separate issue for discussing the second portion would be useful.

Morgan :)

I sent https://dart-review.googlesource.com/c/sdk/+/487160 for the early return and removed it here.

Then I reverted this change to just the optimization, without the special case. You will see it causes some CQ failures, would it be correct to update the test to fix those?

Or we can discuss further on the issue. It currently covers three possible optimizations: deduplicating events (only relevant when there are many events!), the early return (many drivers) and this one (many files). I can add detail and/or split out issues as you like, please let me know. Thanks :)

Open in Gerrit

Related details

Attention is currently required from:
  • Konstantin Shcheglov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I98546cb34ebd6b8c16ae4a902e5b0b2834a1f4e8
Gerrit-Change-Number: 486981
Gerrit-PatchSet: 5
Gerrit-Owner: Morgan :) <david...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Morgan :) <david...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Comment-Date: Wed, 11 Mar 2026 17:11:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Konstantin Shcheglov (Gerrit)

unread,
Mar 11, 2026, 5:31:45 PMMar 11
to Morgan :), Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Morgan :)

Konstantin Shcheglov added 1 comment

File pkg/analyzer/lib/src/dart/analysis/library_context.dart
Konstantin Shcheglov

I don't know out of head why this happens.
It looks that one of the sanity check triggerred.
I think we need to find the root cause.

Open in Gerrit

Related details

Attention is currently required from:
  • Morgan :)
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I98546cb34ebd6b8c16ae4a902e5b0b2834a1f4e8
Gerrit-Change-Number: 486981
Gerrit-PatchSet: 5
Gerrit-Owner: Morgan :) <david...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Morgan :) <david...@google.com>
Gerrit-Attention: Morgan :) <david...@google.com>
Gerrit-Comment-Date: Wed, 11 Mar 2026 21:31:43 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Morgan :) (Gerrit)

unread,
Mar 12, 2026, 6:30:01 AMMar 12
to Konstantin Shcheglov, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Konstantin Shcheglov

Morgan :) added 1 comment

File pkg/analyzer/lib/src/dart/analysis/library_context.dart
Morgan :)

Happy to dig into it.

First though I wanted to take a step back and discuss why it matters, so hopefully we can agree that some fix is needed :)

I added a lot more detail on

https://github.com/dart-lang/sdk/issues/62760#issuecomment-4045624349

please take a look and see what you think.

Open in Gerrit

Related details

Attention is currently required from:
  • Konstantin Shcheglov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I98546cb34ebd6b8c16ae4a902e5b0b2834a1f4e8
Gerrit-Change-Number: 486981
Gerrit-PatchSet: 5
Gerrit-Owner: Morgan :) <david...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Morgan :) <david...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Comment-Date: Thu, 12 Mar 2026 10:29:56 +0000
satisfied_requirement
unsatisfied_requirement
open
diffy

Morgan :) (Gerrit)

unread,
Mar 13, 2026, 12:08:52 PMMar 13
to Konstantin Shcheglov, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Konstantin Shcheglov

Morgan :) added 1 comment

Patchset-level comments
Open in Gerrit

Related details

Attention is currently required from:
  • Konstantin Shcheglov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I98546cb34ebd6b8c16ae4a902e5b0b2834a1f4e8
Gerrit-Change-Number: 486981
Gerrit-PatchSet: 5
Gerrit-Owner: Morgan :) <david...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Morgan :) <david...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Comment-Date: Fri, 13 Mar 2026 16:08:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Morgan :) (Gerrit)

unread,
Mar 13, 2026, 12:08:58 PMMar 13
to Konstantin Shcheglov, Commit Queue, dart-analys...@google.com, rev...@dartlang.org

Morgan :) abandoned this change.

View Change

Morgan :) abandoned this change

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: abandon
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages