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

Use toList(growable: false) more #3151

Merged
merged 2 commits into from
Sep 13, 2022
Merged

Conversation

srawlins
Copy link
Member

I looked through every toList() call, for the ones which could be growable: false, and looked at Observatory's allocation profile, before and after, when documenting package:collection. Here are the result of 3 runs, excluding a 4th run outlier:

  • Used MB: 444 (before) ⟶ 411 (after) -- 7% reduction
  • Allocated MB: 464 (before) ⟶ 450 (after) -- 3% reduction
  • _List instance MBs: 149 (before) ⟶ 129 (after) -- 13% reduction
  • _List instances: 868510 (before) ⟶ 870317 (after) -- 0% reduction
  • _GrowableList instance MBs: 15.1 (before) ⟶ 13.3 (after) -- 12% reduction
  • _GrowableList instances: 495092 (before) ⟶ 435337 (after) -- 12% reduction

I can't super explain these. The reduction in _GrowableLists is expected. But why did the MBs of _List also shrink dramatically? 🤷

Copy link
Collaborator

@keertip keertip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mkustermann
Copy link
Member

I can't super explain these. The reduction in _GrowableLists is expected. But why did the MBs of _List also shrink dramatically? 🤷

Growable list is a wrapper object and a backing store. The backing store grows by power-of-2. By switching to non-growable list, you avoid the wrapper object and shrink the backing store to the precise length you need it (modulo some VM-specifics, we round up to even number of slots).

@srawlins
Copy link
Member Author

Ah perfect, thanks so much for the explanation!

@srawlins srawlins merged commit b0b0d6a into dart-lang:master Sep 13, 2022
@srawlins srawlins deleted the growable-false branch September 13, 2022 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants