Skip to content

Commit e52f01c

Browse files
[Impeller] Execute PipelineCompileQueue jobs in the order that they were added (#190262)
ContentContext tries to create the most commonly used shaders first. But previously the PipelineCompileQueue was using an unordered map to store the shader compilation jobs, which made it iterate through the jobs in arbitrary order. This means that the queue may not build the most needed shaders earliest in the background. If these shaders are not built before the raster thread needs them, then the raster thread will need to spend time building them on demand. This PR changes PipelineCompileQueue to use an Abseil linked hash map that retains the order in which elements are inserted. PipelineCompileQueue will then build the shaders in the order that they were added by ContentContext.
1 parent 347b5a0 commit e52f01c

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎engine/src/flutter/impeller/renderer/BUILD.gn‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impeller_component("renderer") {
9898

9999
deps = [
100100
"//flutter/fml",
101+
"//third_party/abseil-cpp/absl/container:linked_hash_map",
101102
"//third_party/abseil-cpp/absl/strings",
102103
]
103104
}

‎engine/src/flutter/impeller/renderer/pipeline_compile_queue.h‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
#ifndef FLUTTER_IMPELLER_RENDERER_PIPELINE_COMPILE_QUEUE_H_
66
#define FLUTTER_IMPELLER_RENDERER_PIPELINE_COMPILE_QUEUE_H_
77

8-
#include <unordered_map>
9-
108
#include "flutter/fml/closure.h"
119
#include "flutter/fml/concurrent_message_loop.h"
1210
#include "impeller/base/thread.h"
1311
#include "impeller/renderer/pipeline_descriptor.h"
12+
#include "third_party/abseil-cpp/absl/container/linked_hash_map.h"
1413

1514
namespace impeller {
1615

@@ -125,10 +124,10 @@ class PipelineCompileQueue
125124

126125
private:
127126
Mutex pending_jobs_mutex_;
128-
std::unordered_map<PipelineDescriptor,
129-
fml::closure,
130-
ComparableHash<PipelineDescriptor>,
131-
ComparableEqual<PipelineDescriptor>>
127+
absl::linked_hash_map<PipelineDescriptor,
128+
fml::closure,
129+
ComparableHash<PipelineDescriptor>,
130+
ComparableEqual<PipelineDescriptor>>
132131
pending_jobs_ IPLR_GUARDED_BY(pending_jobs_mutex_);
133132
size_t priorities_elevated_ = {};
134133
fml::closure TakeJob(const PipelineDescriptor& desc);

‎engine/src/flutter/impeller/renderer/pipeline_compile_queue_unittests.cc‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class TestPipelineCompileQueue : public PipelineCompileQueue {
2727
}
2828

2929
bool HasPendingJobsForTest() { return HasPendingJobs(); }
30+
31+
void DoOneJobForTest() { DoOneJob(); }
3032
};
3133

3234
TEST(PipelineCompileQueueTest, AddJobReturnsTrueForNewDescriptor) {
@@ -92,5 +94,27 @@ TEST(PipelineCompileQueueTest, FinishAllJobsDrainsQueue) {
9294
EXPECT_TRUE(job_executed);
9395
}
9496

97+
TEST(PipelineCompileQueueTest, ExecutesJobsInInsertionOrder) {
98+
constexpr size_t kJobCount = 10;
99+
auto queue = std::make_shared<TestPipelineCompileQueue>();
100+
101+
std::vector<size_t> job_order;
102+
for (size_t i = 0; i < kJobCount; i++) {
103+
PipelineDescriptor desc;
104+
desc.SetLabel(std::to_string(i));
105+
ASSERT_TRUE(queue->AddJobForTest(
106+
desc, [&job_order, index = i] { job_order.push_back(index); }));
107+
}
108+
109+
for (size_t i = 0; i < kJobCount; i++) {
110+
queue->DoOneJobForTest();
111+
}
112+
113+
EXPECT_EQ(job_order.size(), kJobCount);
114+
for (size_t i = 0; i < kJobCount; i++) {
115+
EXPECT_EQ(i, job_order[i]);
116+
}
117+
}
118+
95119
} // namespace testing
96120
} // namespace impeller

0 commit comments

Comments
 (0)