Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@flar
Copy link
Contributor

@flar flar commented Oct 24, 2024

After landing #54676 we had the DLBuilder using legacy size fields in the DLOp records to manage traversing the records, but we constructed a more direct "offset vector" for the DisplayList to enable random access to the ops. The offset vector was created on the fly during the Build() method and then the size fields in the DLOp records were largely unused and redundant.

This PR gets rid of the remaining uses of the DLOp size fields and has the Builder produce the offsets vector directly during recording.

uint32_t size : 24;
explicit DLOp(DisplayListOpType type) : type(type) {}

const DisplayListOpType type;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[Note to reviewers]
The elimination of the size field was the only change really needed in this file, but for some reason deleting that field caused clang-tidy to complain about the type field being uninitialized on every object below. So, I needed to add a parent initializer to every constructor below.

In the end, this is probably a good thing as it allowed me to make the type field const representing its important static role in the identity of the records.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(But it led to an annoying level of changes to review. Apologies...)

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

Small comment on vector treatment


storage_.realloc(bytes);
storage_.trim();
offsets_.shrink_to_fit();
Copy link
Contributor

Choose a reason for hiding this comment

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

I probably would not use shrink_to_fit here since it may imply another O(N) copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a shrink on copy then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We've always been trimming the storage, though.

How often is realloc(smaller) another allocation and copy?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know about realloc, I just mean for the std::vector.

from https://cplusplus.com/reference/vector/vector/shrink_to_fit/

This may cause a reallocation, but has no effect on the vector size and cannot alter its elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With the change to swap mentioned in the other comment, I still trim the storage because we used to do that, but not the offsets since we have no back history of that.

I can eliminate the storage trim in a separate PR so we can track that independently.

I can also investigate if trimming the offsets makes a difference. std::vector seems to use a doubling algorithm which means we could be using twice the storage for the vectors. I'm still not convinced that shrinking it will require an allocation...

Copy link
Contributor

Choose a reason for hiding this comment

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

shrinking it may require an allocation, as the reference says. 🤷‍♂️


storage_.realloc(bytes);
storage_.trim();
offsets_.shrink_to_fit();
Copy link
Contributor

Choose a reason for hiding this comment

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

Also if the DLBuilder is meant to be reset I think you may need to swap in a new vector because I don't think std::move is guaranteed to reset it to a neutral state like it does for pointers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We test reusability. I've been wanting to get rid of re-usability for a while now, but I think there is some code somewhere that relied on that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah it would be good to remove it, because then we can have build simply take the memory and leave this object in an invalid state

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I switched to more deliberate uses of std::swap to transfer the data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing reusability is a job for a separate PR as it will have potential consequences outside of this part of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(There is already an issue filed for that) flutter/flutter#126589

@flar flar requested a review from jonahwilliams October 24, 2024 21:28
Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@flar flar added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 25, 2024
@auto-submit auto-submit bot merged commit c4b0184 into flutter:main Oct 25, 2024
30 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 25, 2024
nick9822 pushed a commit to nick9822/flutter that referenced this pull request Dec 18, 2024
…ne#56101)

After landing flutter/engine#54676 we had the DLBuilder using legacy size fields in the DLOp records to manage traversing the records, but we constructed a more direct "offset vector" for the DisplayList to enable random access to the ops. The offset vector was created on the fly during the `Build()` method and then the size fields in the DLOp records were largely unused and redundant.

This PR gets rid of the remaining uses of the DLOp size fields and has the Builder produce the offsets vector directly during recording.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants