From f838f6f94f9d3f241f7bc2c3cc066cc9d43da604 Mon Sep 17 00:00:00 2001 From: Steven Wang Date: Tue, 7 Mar 2023 04:13:48 +0000 Subject: [PATCH 1/2] Improve "ExecCtx::RunList()" with O(1) implementation. We don't have to iterate through the list for combining the two lists. They can be combined directly. It can improve the performance. --- src/core/lib/iomgr/exec_ctx.cc | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 65cd319d20cb2..c5c3e2d8417bb 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -106,27 +106,18 @@ void ExecCtx::Run(const DebugLocation& location, grpc_closure* closure, } void ExecCtx::RunList(const DebugLocation& location, grpc_closure_list* list) { - (void)location; - grpc_closure* c = list->head; - while (c != nullptr) { - grpc_closure* next = c->next_data.next; -#ifndef NDEBUG - if (c->scheduled) { - Crash(absl::StrFormat( - "Closure already scheduled. (closure: %p, created: [%s:%d], " - "previously scheduled at: [%s: %d], newly scheduled at [%s:%d]", - c, c->file_created, c->line_created, c->file_initiated, - c->line_initiated, location.file(), location.line())); + grpc_closure_list* destlist = grpc_core::ExecCtx::Get()->closure_list(); + + if (list->head != nullptr) { + if (destlist->head == nullptr) { + destlist->head = list->head; + destlist->tail = list->tail; + } else { + destlist->tail->next_data.next = list->head; + destlist->tail = list->tail; } - c->scheduled = true; - c->file_initiated = location.file(); - c->line_initiated = location.line(); - c->run = false; - GPR_ASSERT(c->cb != nullptr); -#endif - exec_ctx_sched(c); - c = next; } + list->head = list->tail = nullptr; } From cc7424fceb2c64bd9d97cf27deceb74897e5fef8 Mon Sep 17 00:00:00 2001 From: LeiW000 Date: Tue, 7 Mar 2023 07:15:26 +0000 Subject: [PATCH 2/2] Automated change: Fix sanity tests --- src/core/lib/iomgr/exec_ctx.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index c5c3e2d8417bb..924a7e9b0d6f7 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -106,7 +106,7 @@ void ExecCtx::Run(const DebugLocation& location, grpc_closure* closure, } void ExecCtx::RunList(const DebugLocation& location, grpc_closure_list* list) { - grpc_closure_list* destlist = grpc_core::ExecCtx::Get()->closure_list(); + grpc_closure_list* destlist = ExecCtx::Get()->closure_list(); if (list->head != nullptr) { if (destlist->head == nullptr) {