[#47790] [ruby-trunk - Bug #7097][Open] Thread locals don't work inside Enumerator — "tenderlovemaking (Aaron Patterson)" <aaron@...>

32 messages 2012/10/01
[#47791] [ruby-trunk - Bug #7097][Assigned] Thread locals don't work inside Enumerator — "kosaki (Motohiro KOSAKI)" <kosaki.motohiro@...> 2012/10/01

[#47792] Re: [ruby-trunk - Bug #7097][Assigned] Thread locals don't work inside Enumerator — Aaron Patterson <tenderlove@...> 2012/10/01

On Tue, Oct 02, 2012 at 03:05:17AM +0900, kosaki (Motohiro KOSAKI) wrote:

[#47798] Re: [ruby-trunk - Bug #7097][Assigned] Thread locals don't work inside Enumerator — SASADA Koichi <ko1@...> 2012/10/01

(2012/10/02 3:12), Aaron Patterson wrote:

[#47800] Re: [ruby-trunk - Bug #7097][Assigned] Thread locals don't work inside Enumerator — SASADA Koichi <ko1@...> 2012/10/01

(2012/10/02 8:22), SASADA Koichi wrote:

[#47832] [ruby-trunk - Feature #7106][Open] FileUtils.touch should allow touching the symlink itself rather than the file the link points to — "cirrusthinking (Alessandro Diaferia)" <alessandro@...>

18 messages 2012/10/04

[#47847] [ruby-trunk - Bug #7110][Open] CGI: Add support for HTML5 <header> tag — "stomar (Marcus Stollsteimer)" <redmine@...>

16 messages 2012/10/05

[#47870] [ruby-trunk - Bug #7123][Open] Segmentation fault in ruby 1.9.3-p194 — "mscottford (M. Scott Ford)" <scott@...>

13 messages 2012/10/09

[#47880] [ruby-trunk - Bug #7134][Open] Signal handling bug in Mac OS X — "auastro (Andy Kitchen)" <kitchen.andy+rubybug@...>

17 messages 2012/10/10

[#47881] [ruby-trunk - Bug #7135][Open] GC bug in Ruby 1.9.3-p194? — "alexdowad (Alex Dowad)" <alexinbeijing@...>

21 messages 2012/10/10

[#47887] [ruby-trunk - Bug #7137][Open] Date.parse overly lenient when attempting to parse Monday? — "garysweaver (Gary Weaver)" <garysweaver@...>

12 messages 2012/10/10

[#47930] [ruby-trunk - Feature #7148][Open] Improved Tempfile w/o DelegateClass — "Glass_saga (Masaki Matsushita)" <glass.saga@...>

14 messages 2012/10/12

[#47970] [ruby-trunk - Bug #7158][Open] require is slow in its bookkeeping; can make Rails startup 2.2x faster — "gregprice (Greg Price)" <price@...>

30 messages 2012/10/14

[#48027] [Backport93 - Backport #7172][Open] [[Ruby 1.9:]] fix rbconfig for --enable-load-relative (v2) — "mpapis (Michal Papis)" <mpapis@...>

13 messages 2012/10/16

[#48053] [ruby-trunk - Bug #7180][Open] set_trace_func with error in proc block locks up Ruby with 100% cpu usage and no way to exit without killing proc — "garysweaver (Gary Weaver)" <garysweaver@...>

8 messages 2012/10/17

[#48072] [ruby-trunk - Bug #7184][Open] --disable-gems commandline parameter does not show up with ruby -h — "steenslag (siep korteling)" <s.korteling@...>

10 messages 2012/10/18

[#48130] [ruby-trunk - Bug #7200][Open] Setting external encoding with BOM| — "brixen (Brian Ford)" <brixen@...>

14 messages 2012/10/21

[#48191] [ANN] 2.0.0 feature freeze — Yusuke Endoh <mame@...>

Japanese later; 日本語は後で

37 messages 2012/10/24
[#48696] Re: [ANN] 2.0.0 feature freeze — SASADA Koichi <ko1@...> 2012/11/01

(2012/10/24 5:39), Yusuke Endoh wrote:

[#48260] [ruby-trunk - Bug #7214][Open] Ruby 2.0 breaks support for some debugging tools — "banister (john mair)" <jrmair@...>

22 messages 2012/10/25

[#48315] [ruby-trunk - Bug #7220][Open] StringIO#initialize_copy causes aliasing between the objects — "brixen (Brian Ford)" <brixen@...>

13 messages 2012/10/26

[#48413] [ruby-trunk - Bug #7221][Open] Unable to compile kgio under 1.9.3 with error: ruby-1.9.3-<plvl>/lib/ruby/1.9.1/mkmf.rb:597:in `Integer': can't convert nil into Integer (TypeError) — "davidderyldowney (David Deryl Downey)" <me@...>

9 messages 2012/10/27

[#48549] [ruby-trunk - Feature #7240][Open] Inheritable #included/#extended Hooks For Modules — "apotonick (Nick Sutterer)" <apotonick@...>

14 messages 2012/10/29

[#48551] [ruby-trunk - Feature #7241][Open] Enumerable#to_h proposal — "nathan.f77 (Nathan Broadbent)" <nathan.f77@...>

23 messages 2012/10/29

[#48552] [ruby-trunk - Bug #7242][Open] Bignum mathematical accuracy regression in r31695 — "mhall (Matthew Hall)" <mhall@...>

11 messages 2012/10/29

[ruby-core:48536] Re: [ruby-trunk - Bug #7158] require is slow in its bookkeeping; can make Rails startup 2.2x faster

From: =?KOI8-R?B?4NLJyiDzz8vPzM/X?= <funny.falcon@...>
Date: 2012-10-29 04:58:09 UTC
List: ruby-core #48536
Which way insertion into sorted array takes same O(n) time? Do you mean
cost of memcpy after finding position for insert? Despite memcpy (which I
be leave cheap on this amounts) cost of insertion is O(log n).
Can you show result with caching LOAD_PATH and without indexing
LOADED_FEATURES? I believe that indexing will add small improvement after
caching.

28.10.2012 5:30 ミマフリレマラチヤナフリ "gregprice (Greg Price)" <price@mit.edu>
ホチミノモチフ:
>
>
> Issue #7158 has been updated by gregprice (Greg Price).
>
>
> Sasada-san, thank you for the review.  You're right, patch (4) should
(and doesn't) invalidate the cache when the working directory changes.  I
believe Yura is right that it should also invalidate the cache when the
filesystem encoding changes.
>
> Yura, thanks for your existing patches and your detailed comments.  At
first look, I suspect that the reason a sorted-list approach to
$LOADED_FEATURES was not a major speedup is that insertion is slow -- it
takes time O(n), on the same order as the lookup takes in trunk.  So it
should still be helpful when one does many 'require' calls on the same
files, but not as much as if insertion is also fast.  With the
hash-table-based index in (3), insertion takes time O(p), where p ~= 10 is
the number of path components in the library filenames, and lookup is O(1)
except in pathological cases.
>
> I'm not too worried about recomputing the $LOAD_PATH cache from scratch
after it's modified. For one thing, we do so only in an actual 'require'
call, and it's only as expensive as the computation we do now in trunk on
every 'require' call, so there's no case in which it should cause a
regression. I suspect it's also the case that in common usage (with e.g.
Bundler) most $LOAD_PATH modifications happen all at once with no
intervening 'require' calls, and in that case we will only recompute it
once for all of those changes. (But I haven't checked that that's the
case.) So I think the trade-off of recomputing from scratch with less code
complexity is a good one.
>
> Shirosaki-san, thanks for your additional patches. I'm reading them now.
>
> ----------------------------------------
> Bug #7158: require is slow in its bookkeeping; can make Rails startup
2.2x faster
> https://bugs.ruby-lang.org/issues/7158#change-31844
>
> Author: gregprice (Greg Price)
> Status: Assigned
> Priority: Normal
> Assignee: ko1 (Koichi Sasada)
> Category: core
> Target version:
> ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35409) [i686-linux]
>
>
> =begin
> Starting a large application in Ruby is slow.  Most of the startup
> time is not spent in the actual work of loading files and running Ruby
> code, but in bookkeeping in the 'require' implementation.  I've
> attached a patch series which makes that bookkeeping much faster.
> These patches speed up a large Rails application's startup by 2.2x,
> and a pure-'require' benchmark by 3.4x.
>
> These patches fix two ways in which 'require' is slow.  Both problems
> have been discussed before, but these patches solve the problems with
> less code and stricter compatibility than previous patches I've seen.
>
> * Currently we iterate through $LOADED_FEATURES to see if anything
>   matches the newly required feature.  Further, each iteration
>   iterates in turn through $LOAD_PATH.  Xavier Shay spotted this
>   problem last year and a series of patches were discussed
>   (in Issue #3924) to add a Hash index alongside $LOADED_FEATURES,
>   but for 1.9.3 none were merged; Masaya Tarui committed Revision r31875,
>   which mitigated the problem.  This series adds a Hash index,
>   and keeps it up to date even if the user modifies $LOADED_FEATURES.
>   This is worth a 40% speedup on one large Rails application,
>   and 2.3x on a pure-'require' benchmark.
>
> * Currently each 'require' call runs through $LOAD_PATH and calls
>   rb_file_expand_path() on each element.  Yura Sokolov (funny_falcon)
>   proposed caching this last December in Issue #5767, but it wasn't
>   merged.  This series also caches $LOAD_PATH, and keeps the cache up
>   to date with a different, less invasive technique.  The cache takes
>   34 lines of code, and is worth an additional 57% speedup in
>   starting a Rails app and a 46% speedup in pure 'require'.
>
>
> == Staying Compatible
>
> With both the $LOADED_FEATURES index and the $LOAD_PATH cache,
>
> * we exactly preserve the semantics of the user modifying $LOAD_PATH
>   or $LOADED_FEATURES;
>
> * both $LOAD_PATH and $LOADED_FEATURES remain ordinary Arrays, with
>   no singleton methods;
>
> * we make just one semantic change: each element of $LOAD_PATH and
>   $LOADED_FEATURES is made into a frozen string.  This doesn't limit
>   the flexibility Ruby offers to the programmer in any way; to alter
>   an element of either array, one simply reassigns it to the new
>   value.  Further, normal path-munging code which only adds and
>   removes elements shouldn't have to change at all.
>
> These patches use the following technique to keep the cache and the
> index up to date without modifying the methods of $LOADED_FEATURES or
> $LOAD_PATH: we take advantage of the sharing mechanism in the Array
> implementation to detect, in O(1) time, whether either array has been
> mutated.  We cause $LOADED_FEATURES to be shared with an Array we keep
> privately in load.c; if anything modifies it, it will break the
> sharing and we will know to rebuild the index.  Similarly for
> $LOAD_PATH.
>
>
> == Benchmarks
>
> First, on my company's Rails application, where $LOAD_PATH.size is 207
> and $LOADED_FEATURES.size is 2126.  I measured the time taken by
> 'bundle exec rails runner "p 1"'.
>
>  .                Rails startup time,
>  version               best of 5        speedup
>  v1_9_3_194             12.197s
>  v1_9_3_194+index        8.688s          1.40x
>  v1_9_3_194+index+cache  5.538s          2.20x
>
> And now isolating the performance of 'require', by requiring
> 16000 empty files.
>
>  version            time, best of 5     speedup
>  trunk (at r36920)      10.115s
>  trunk+index             4.363s          2.32x
>  trunk+index+cache       2.984s          3.39x
>
> (The timings for the Rails application are based on the latest release
> rather than trunk because a number of gems failed to compile against
> trunk for me.)
>
>
> == The Patches
>
> I've attached four patches:
>
> (1) Patch 1 changes no behavior at all.  It adds comments and
>     simplifies a bit of code to help in understanding why patch 3 is
>     correct.  42 lines, most of them comments.
>
> (2) Patch 2 adds a function to array.c which will help us tell when
>     $LOAD_PATH or $LOADED_FEATURES has been modified.  17 lines.
>
> (3) Patch 3 adds the $LOADED_FEATURES index.  150 lines.
>
> (4) Patch 4 adds the $LOAD_PATH cache.  34 lines.
>
> Reviews and comments welcome -- I'm sure there's something I could do
> to make these patches better.  I hope we can get some form of them
> into trunk before the next release.  My life has been happier since I
> switched to this version because commands in my Rails application all
> run faster now, and I want every Ruby programmer to be happier in the
> same way with 2.0 and ideally with 1.9.4.
>
> =end
>
>
>
> --
> http://bugs.ruby-lang.org/
>

In This Thread