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

Commit f4c20e9

Browse files
author
Jonah Williams
authored
[Impeller] remove image upload from IO thread, limit concurrent worker threads. (#52423)
Fixes flutter/flutter#123058 Fixes flutter/flutter#135443 We're currently using the IO thread to bottleneck image uploads. Instead, just use fewer concurrent worker threads - and cap the limit at something small. For a Pixel device, this should use about 2 threads maximum, instead of 5 (4 worker and 1 IO).
1 parent dbeec53 commit f4c20e9

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

lib/ui/painting/image_decoder_impeller.cc

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
#include "flutter/fml/make_copyable.h"
1111
#include "flutter/fml/trace_event.h"
1212
#include "flutter/impeller/core/allocator.h"
13-
#include "flutter/impeller/core/texture.h"
1413
#include "flutter/impeller/display_list/dl_image_impeller.h"
1514
#include "flutter/impeller/renderer/command_buffer.h"
1615
#include "flutter/impeller/renderer/context.h"
17-
#include "flutter/lib/ui/painting/image_decoder_skia.h"
1816
#include "impeller/base/strings.h"
1917
#include "impeller/core/device_buffer.h"
2018
#include "impeller/display_list/skia_conversions.h"
@@ -489,29 +487,21 @@ void ImageDecoderImpeller::Decode(fml::RefPtr<ImageDescriptor> descriptor,
489487
result(nullptr, bitmap_result.decode_error);
490488
return;
491489
}
492-
auto upload_texture_and_invoke_result = [result, context, bitmap_result,
493-
gpu_disabled_switch]() {
494-
sk_sp<DlImage> image;
495-
std::string decode_error;
496-
if (context->GetCapabilities()->SupportsBufferToTextureBlits()) {
497-
std::tie(image, decode_error) = UploadTextureToPrivate(
498-
context, bitmap_result.device_buffer, bitmap_result.image_info,
499-
bitmap_result.sk_bitmap, gpu_disabled_switch);
500-
result(image, decode_error);
501-
} else {
502-
std::tie(image, decode_error) = UploadTextureToStorage(
503-
context, bitmap_result.sk_bitmap, gpu_disabled_switch,
504-
impeller::StorageMode::kDevicePrivate,
505-
/*create_mips=*/true);
506-
result(image, decode_error);
507-
}
508-
};
509-
// TODO(jonahwilliams):
510-
// https://github.com/flutter/flutter/issues/123058 Technically we
511-
// don't need to post tasks to the io runner, but without this
512-
// forced serialization we can end up overloading the GPU and/or
513-
// competing with raster workloads.
514-
io_runner->PostTask(upload_texture_and_invoke_result);
490+
491+
sk_sp<DlImage> image;
492+
std::string decode_error;
493+
if (context->GetCapabilities()->SupportsBufferToTextureBlits()) {
494+
std::tie(image, decode_error) = UploadTextureToPrivate(
495+
context, bitmap_result.device_buffer, bitmap_result.image_info,
496+
bitmap_result.sk_bitmap, gpu_disabled_switch);
497+
result(image, decode_error);
498+
} else {
499+
std::tie(image, decode_error) = UploadTextureToStorage(
500+
context, bitmap_result.sk_bitmap, gpu_disabled_switch,
501+
impeller::StorageMode::kDevicePrivate,
502+
/*create_mips=*/true);
503+
result(image, decode_error);
504+
}
515505
});
516506
}
517507

runtime/dart_vm.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,19 @@ size_t DartVM::GetVMLaunchCount() {
282282
return gVMLaunchCount;
283283
}
284284

285+
// Minimum and maximum number of worker threads.
286+
static constexpr size_t kMinCount = 2;
287+
static constexpr size_t kMaxCount = 4;
288+
285289
DartVM::DartVM(const std::shared_ptr<const DartVMData>& vm_data,
286290
std::shared_ptr<IsolateNameServer> isolate_name_server)
287291
: settings_(vm_data->GetSettings()),
288292
concurrent_message_loop_(fml::ConcurrentMessageLoop::Create(
289-
fml::EfficiencyCoreCount().value_or(
290-
std::thread::hardware_concurrency()))),
293+
std::clamp(fml::EfficiencyCoreCount().value_or(
294+
std::thread::hardware_concurrency()) /
295+
2,
296+
kMinCount,
297+
kMaxCount))),
291298
skia_concurrent_executor_(
292299
[runner = concurrent_message_loop_->GetTaskRunner()](
293300
const fml::closure& work) { runner->PostTask(work); }),

shell/platform/embedder/tests/embedder_unittests.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,6 +2310,8 @@ TEST_F(EmbedderTest, CanPostTaskToAllNativeThreads) {
23102310
ASSERT_EQ(captures.render_threads_count, 1u);
23112311
ASSERT_EQ(captures.ui_threads_count, 1u);
23122312
ASSERT_EQ(captures.worker_threads_count, worker_count + 1u /* for IO */);
2313+
EXPECT_GE(captures.worker_threads_count - 1, 2u);
2314+
EXPECT_LE(captures.worker_threads_count - 1, 4u);
23132315

23142316
platform_task_runner->PostTask([&]() {
23152317
engine.reset();

0 commit comments

Comments
 (0)