Skip to content

Commit 56d4ac0

Browse files
authored
[impeller] gles: started storing the number of handle deletions to avoid reallocation (flutter#56799)
I saw in profiles that we were spending a lot of time in push_back_slow_path. Reserving + emplacing removes that. test-except: no functional change, performance increase ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent 258666b commit 56d4ac0

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

impeller/renderer/backend/gles/reactor_gles.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ HandleGLES ReactorGLES::CreateHandle(HandleType type, GLuint external_handle) {
219219
void ReactorGLES::CollectHandle(HandleGLES handle) {
220220
WriterLock handles_lock(handles_mutex_);
221221
if (auto found = handles_.find(handle); found != handles_.end()) {
222+
if (!found->second.pending_collection) {
223+
handles_to_collect_count_ += 1;
224+
}
222225
found->second.pending_collection = true;
223226
}
224227
}
@@ -273,10 +276,12 @@ bool ReactorGLES::ConsolidateHandles() {
273276
handles_to_name;
274277
{
275278
WriterLock handles_lock(handles_mutex_);
279+
handles_to_delete.reserve(handles_to_collect_count_);
280+
handles_to_collect_count_ = 0;
276281
for (auto& handle : handles_) {
277282
// Collect dead handles.
278283
if (handle.second.pending_collection) {
279-
handles_to_delete.push_back(
284+
handles_to_delete.emplace_back(
280285
std::make_tuple(handle.first, handle.second.name));
281286
continue;
282287
}
@@ -292,7 +297,7 @@ bool ReactorGLES::ConsolidateHandles() {
292297
// Set pending debug labels.
293298
if (handle.second.pending_debug_label.has_value() &&
294299
handle.first.type != HandleType::kFence) {
295-
handles_to_name.push_back(std::make_tuple(
300+
handles_to_name.emplace_back(std::make_tuple(
296301
ToDebugResourceType(handle.first.type),
297302
handle.second.name.value().handle,
298303
std::move(handle.second.pending_debug_label.value())));

impeller/renderer/backend/gles/reactor_gles.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class ReactorGLES {
284284
HandleGLES::Equal>;
285285
mutable RWMutex handles_mutex_;
286286
LiveHandles handles_ IPLR_GUARDED_BY(handles_mutex_);
287+
int32_t handles_to_collect_count_ IPLR_GUARDED_BY(handles_mutex_) = 0;
287288

288289
mutable Mutex workers_mutex_;
289290
mutable std::map<WorkerID, std::weak_ptr<Worker>> workers_ IPLR_GUARDED_BY(

0 commit comments

Comments
 (0)