Non-main thread making mojo calls while main thread is busy

10 lượt xem
Chuyển tới thư đầu tiên chưa đọc

Koji Ishii

chưa đọc,
04:59:28 21 thg 10, 202121/10/21
đến chromium-mojo
Hi mojo experts,

I'm having trouble calling mojo from a ThreadPool thread and appreciate your advice.

Loading fonts to the renderer process is expensive, often ~15% of the total layout time. I'm trying to move this out of the main thread.

This involves a ThreadPool thread making a mojo call. To get a mojo::remote, as far as I understand, I need to post a task to the main thread.
      main_task_runner_->PostTask(
          FROM_HERE, base::BindOnce(&BindHostReceiverOnMainThread,
                                    font_proxy.BindNewPipeAndPassReceiver()));

The execution of this code, and therefore following the actual mojo calls, seem to be delayed until sometime -- I guess probably the main thread goes back to the event loop. This is causing two problems:
  • The font loading doesn't start at the point I wish to start.
  • When the main thread tries to read the loaded font, it hits a deadlock.
Now I'm thinking, if I use a WorkerTherad instead of ThreadPool, and post the BindHostReceiver task earlier (when the main thread can run posted tasks), actual mojo calls may be able to run without requiring the main thread to go back to the event loop.

Does my observation and hypothesis seem to be correct? Can anyone see other advice?

Your support is greatly appreciated in advance.

Koji Ishii

chưa đọc,
05:46:06 21 thg 10, 202121/10/21
đến chromium-mojo
Self-follow after more investigation. I found base::ThreadPool::CreateSingleThreadTaskRunner and this seems to solve the problem.
Trả lời tất cả
Trả lời tác giả
Chuyển tiếp
0 tin nhắn mới