diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-01 21:19:24 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-01 21:19:24 +0000 |
commit | e552afc30ee8f225ed7b6f798cb783ef08d7a737 (patch) | |
tree | 2f622b4b4caeefe6aaf3db1683e1b42b305c7baa /file.c | |
parent | f01846cdc84975748717aa049442896ff3a04a8f (diff) |
File#rename releases GVL
rename(2) requires two pathname resolution operations which can
take considerable time on slow filesystems, release the GVL so
operations on other threads may proceed.
On fast, local filesystems, this change results in some slowdown
as shown by the new benchmark. I consider the performance trade
off acceptable as cases are avoided.
benchmark results:
minimum results in each 3 measurements.
Execution time (sec)
name trunk built
file_rename 2.648 2.804
Speedup ratio: compare with the result of `trunk' (greater is better)
name built
file_rename 0.944
* file.c (no_gvl_rename): new function
(rb_file_s_rename): release GVL for renames
* benchmark/bm_file_rename.rb: new benchmark
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -2873,6 +2873,19 @@ rb_file_s_unlink(int argc, VALUE *argv, VALUE klass) return apply2files(unlink_internal, argc, argv, 0); } +struct rename_args { + const char *src; + const char *dst; +}; + +static void * +no_gvl_rename(void *ptr) +{ + struct rename_args *ra = ptr; + + return (void *)(VALUE)rename(ra->src, ra->dst); +} + /* * call-seq: * File.rename(old_name, new_name) -> 0 @@ -2886,19 +2899,20 @@ rb_file_s_unlink(int argc, VALUE *argv, VALUE klass) static VALUE rb_file_s_rename(VALUE klass, VALUE from, VALUE to) { - const char *src, *dst; + struct rename_args ra; VALUE f, t; FilePathValue(from); FilePathValue(to); f = rb_str_encode_ospath(from); t = rb_str_encode_ospath(to); - src = StringValueCStr(f); - dst = StringValueCStr(t); + ra.src = StringValueCStr(f); + ra.dst = StringValueCStr(t); #if defined __CYGWIN__ errno = 0; #endif - if (rename(src, dst) < 0) { + if ((int)(VALUE)rb_thread_call_without_gvl(no_gvl_rename, &ra, + RUBY_UBF_IO, 0) < 0) { int e = errno; #if defined DOSISH switch (e) { |