[#85349] [Ruby trunk Bug#14334] Segmentation fault after running rspec (ruby/2.5.0/erb.rb:885 / simplecov/source_file.rb:85) — pragtob@...
Issue #14334 has been updated by PragTob (Tobias Pfeiffer).
3 messages
2018/02/02
[#85358] Re: [ruby-cvs:69220] nobu:r62039 (trunk): compile.c: unnecessary freezing — Eric Wong <normalperson@...>
[email protected] wrote:
5 messages
2018/02/03
[#85612] Why require autoconf 2.67+ — leam hall <leamhall@...>
Please pardon the intrusion; I am new to Ruby and like to pull the
6 messages
2018/02/17
[#85616] Re: Why require autoconf 2.67+
— Vít Ondruch <v.ondruch@...>
2018/02/18
VGhpcyBjb3VsZCBoZWxwIHlvdSB0byBidWlsZCBSdWJ5IHdpdGggb2xkZXIgYXV0b2NvbmYgKDIu
[#85634] [Ruby trunk Bug#14494] [PATCH] tool/m4/ruby_replace_type.m4 use AC_CHECK_TYPES for HAVE_* macros — normalperson@...
Issue #14494 has been reported by normalperson (Eric Wong).
3 messages
2018/02/19
[#85674] [Ruby trunk Feature#13618] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — matz@...
Issue #13618 has been updated by matz (Yukihiro Matsumoto).
5 messages
2018/02/20
[#85686] Re: [Ruby trunk Feature#13618] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid
— Eric Wong <normalperson@...>
2018/02/20
[email protected] wrote:
[#85704] Re: [Ruby trunk Feature#13618] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid
— Koichi Sasada <ko1@...>
2018/02/21
On 2018/02/20 18:06, Eric Wong wrote:
[ruby-core:85520] [Ruby trunk Feature#14460] Speed up `require` and reduce memory usage
From:
funny.falcon@...
Date:
2018-02-13 10:41:50 UTC
List:
ruby-core #85520
Issue #14460 has been updated by funny_falcon (Yura Sokolov).
Did you compare it with https://bugs.ruby-lang.org/issues/8158 ?
----------------------------------------
Feature #14460: Speed up `require` and reduce memory usage
https://bugs.ruby-lang.org/issues/14460#change-70311
* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Hi,
I've attached a patch that speeds up require and reduces memory usage. Before this patch, we could copy copy keys using `rb_strdup` for the `loaded_features_index` table. This patch changes the hash population functions to just index in to the Ruby strings without copying them. Some of the keys for the index require that the file names do not have a file extension. For that case, I create a new string (so that it's NULL padded), then index in to that string. Rather than coping the string for each `/` in the path, this patch just indexes in to the string. It relies on the loaded features array and the new array I introduced for liveness. `get_loaded_features_index` handles cache invalidation, so I believe it is safe to rely on these two arrays for liveness of the `loaded_features_index` keys.
I tested memory usage by booting a Rails application in production mode (the same test I'm doing with the ISeq patches), and found that it saves about 4.2% memory (59580203 bytes in trunk, 57057395 bytes with this patch). I also found that this patch eliminated 76212 system calls (presumably calls to malloc / free for the hash table keys). Finally, I found that this patch sped up `require` by about 35%.
Here is a graph of the memory usage:

Each sample is a call to malloc, so you can see from the graph that this patch reduces memory usage and system calls.
I ran the `bm_require.rb` benchmark to compare times:
~~~
[aaron@TC-3 ruby (no-dup-string)]$ make benchmark OPTS='-p bm_require.rb'
/Users/aaron/.rbenv/shims/ruby --disable=gems ./benchmark/driver.rb -v \
--executables="/Users/aaron/.rbenv/shims/ruby --disable=gems -I./lib -I. -I.ext/common --disable-gem; built-ruby::./miniruby -I./lib -I. -I.ext/common --disable-gem" \
--pattern='bm_' --directory=./benchmark -p bm_require.rb
2018-02-09 16:25:37 -0800
target 0: ruby 2.6.0dev (2018-02-07 trunk 62271) [x86_64-darwin17] at "/Users/aaron/.rbenv/shims/ruby --disable=gems -I./lib -I. -I.ext/common --disable-gem"
target 1: built-ruby (ruby 2.6.0dev (2018-02-07 trunk 62271) [x86_64-darwin17]) at "./miniruby -I./lib -I. -I.ext/common --disable-gem"
measure target: real
-----------------------------------------------------------
require
$:.push File.join(File.dirname(__FILE__), "bm_require.data")
1.upto(10000) do |i|
require "c#{i}"
end
$:.pop
ruby 2.6.0dev (2018-02-07 trunk 62271) [x86_64-darwin17] 3.043203999997786
built-ruby 1.9892130000007455
-----------------------------------------------------------
raw data:
[["require", [[3.043203999997786], [1.9892130000007455]]]]
Elapsed time: 5.036855 (sec)
-----------------------------------------------------------
benchmark results:
Execution time (sec)
name ruby 2.6.0dev (2018-02-07 trunk 62271) [x86_64-darwin17] built-ruby
require 3.043 1.989
Speedup ratio: compare with the result of `ruby 2.6.0dev (2018-02-07 trunk 62271) [x86_64-darwin17]' (greater is better)
name built-ruby
require 1.530
Log file: bmlog-20180209-162537.60174.tsv
~~~
---Files--------------------------------
0001-Use-shared-substrings-in-feature-index-cache-hash.patch (6.05 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>