From a7797c47b2fde30079fe73db58b66cbea7e974c2 Mon Sep 17 00:00:00 2001 From: normal Date: Sun, 1 Oct 2017 21:19:24 +0000 Subject: 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 --- benchmark/bm_file_rename.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 benchmark/bm_file_rename.rb (limited to 'benchmark/bm_file_rename.rb') diff --git a/benchmark/bm_file_rename.rb b/benchmark/bm_file_rename.rb new file mode 100644 index 0000000000..3bf6a5ef35 --- /dev/null +++ b/benchmark/bm_file_rename.rb @@ -0,0 +1,11 @@ +# rename file +require 'tempfile' + +max = 100_000 +tmp = [ Tempfile.new('rename-a'), Tempfile.new('rename-b') ] +a, b = tmp.map { |x| x.path } +max.times do + File.rename(a, b) + File.rename(b, a) +end +tmp.each { |t| t.close! } -- cgit v1.2.3