From 508091d9cca2559b3f9e8802ce6350ab3cbc36fd Mon Sep 17 00:00:00 2001 From: normal Date: Sat, 20 May 2017 09:47:14 +0000 Subject: speed up IO#close with many threads Today, it increases IO#close performance with many threads: Execution time (sec) name trunk after vm_thread_close 4.276 3.018 Speedup ratio: compare with the result of `trunk' (greater is better) name after vm_thread_close 1.417 This speedup comes because rb_notify_fd_close only scans threads inside rb_thread_io_blocking_region, not all threads in the VM. In the future, this type data structure may allow us to notify waiters of multiple FDs on a single thread (when using Fibers). * thread.c (struct waiting_fd): declare (rb_thread_io_blocking_region): use on-stack list waiter (rb_notify_fd_close): walk vm->waiting_fds instead (call_without_gvl): remove old field setting (th_init): ditto * vm_core.h (typedef struct rb_vm_struct): add waiting_fds list * (typedef struct rb_thread_struct): remove waiting_fd field (rb_vm_living_threads_init): initialize waiting_fds list I am now kicking myself for not thinking about this 3 years ago when I introduced ccan/list in [Feature #9632] to optimize this same function :< git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm.c | 1 - 1 file changed, 1 deletion(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 52d505ab7c..4810321d6f 100644 --- a/vm.c +++ b/vm.c @@ -2521,7 +2521,6 @@ th_init(rb_thread_t *th, VALUE self) th->status = THREAD_RUNNABLE; th->errinfo = Qnil; th->last_status = Qnil; - th->waiting_fd = -1; th->root_svar = Qfalse; th->local_storage_recursive_hash = Qnil; th->local_storage_recursive_hash_for_trace = Qnil; -- cgit v1.2.3