[#101174] [Ruby master Bug#17359] Ractor copy mode is not Ractor-safe — marcandre-ruby-core@...

Issue #17359 has been reported by marcandre (Marc-Andre Lafortune).

17 messages 2020/12/01

[#101217] [Ruby master Feature#17363] Timeouts — marcandre-ruby-core@...

Issue #17363 has been reported by marcandre (Marc-Andre Lafortune).

19 messages 2020/12/03

[#101250] [Ruby master Bug#17369] Introduce non-blocking `Process.wait`, `Kernel.system` and related methods. — samuel@...

Issue #17369 has been reported by ioquatix (Samuel Williams).

12 messages 2020/12/05

[#101276] [Ruby master Bug#17373] Ruby 3.0 is slower at Discourse bench than Ruby 2.7 — sam.saffron@...

Issue #17373 has been reported by sam.saffron (Sam Saffron).

11 messages 2020/12/07

[#101278] [Ruby master Bug#17374] Refined methods aren't visible from a refinementRefinements that include/prepend module — marcandre-ruby-core@...

Issue #17374 has been reported by marcandre (Marc-Andre Lafortune).

17 messages 2020/12/07

[#101317] [Ruby master Feature#17378] Ractor#receive with filtering like other actor langauge — ko1@...

Issue #17378 has been reported by ko1 (Koichi Sasada).

9 messages 2020/12/08

[#101343] [Ruby master Bug#17382] Segfault in String#inspect — lionel.perrin@...

Issue #17382 has been reported by lionelperrin (Lionel Perrin).

10 messages 2020/12/09

[#101381] [Ruby master Bug#17385] Test failures on gcc 11 — jaruga@...

Issue #17385 has been reported by jaruga (Jun Aruga).

18 messages 2020/12/10

[#101458] [Ruby master Bug#17394] TCPServer is not thread safe on win32 — aladjev.andrew@...

Issue #17394 has been reported by puchuu (Andrew Aladjev).

9 messages 2020/12/14

[#101472] [Ruby master Feature#17397] shareable_literal_constant should check at runtime, not at parse time — marcandre-ruby-core@...

Issue #17397 has been reported by marcandre (Marc-Andre Lafortune).

10 messages 2020/12/16

[#101475] [Ruby master Bug#17398] SyntaxError in endless method — zverok.offline@...

Issue #17398 has been reported by zverok (Victor Shepelev).

15 messages 2020/12/16

[#101477] [Ruby master Misc#17399] Are endless methods experimental? — zverok.offline@...

Issue #17399 has been reported by zverok (Victor Shepelev).

13 messages 2020/12/16

[#101480] [Ruby master Bug#17400] Incorrect character downcase for Greek Sigma — xfalcox@...

SXNzdWUgIzE3NDAwIGhhcyBiZWVuIHJlcG9ydGVkIGJ5IHhmYWxjb3ggKFJhZmFlbCBTaWx2YSku

10 messages 2020/12/16

[#101513] [Ruby master Bug#17405] irb ---nomultiline gets exception when output contains some non-ascii characters — rsharman@...

SXNzdWUgIzE3NDA1IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IHJzaGFybWFuIChSaWNoYXJkIFNoYXJt

8 messages 2020/12/18

[#101534] [Ruby master Bug#17409] Endless range of dates stuck on include? when miss — sergey.gnuskov@...

Issue #17409 has been reported by gsmetal (Sergey G).

9 messages 2020/12/19

[#101546] [Ruby master Bug#17411] Syntax error with . in pattern — zverok.offline@...

Issue #17411 has been reported by zverok (Victor Shepelev).

10 messages 2020/12/19

[#101598] [Ruby master Bug#17420] Unsafe mutation of $" when doing non-RubyGems require in Ractor — eregontp@...

Issue #17420 has been reported by Eregon (Benoit Daloze).

12 messages 2020/12/21

[#101635] [Ruby master Bug#17428] Method#inspect bad output for class methods — marcandre-ruby-core@...

Issue #17428 has been reported by marcandre (Marc-Andre Lafortune).

13 messages 2020/12/23

[#101639] [Ruby master Bug#17429] Prohibit include/prepend in refinement modules — shugo@...

Issue #17429 has been reported by shugo (Shugo Maeda).

32 messages 2020/12/23

[#101707] [Ruby master Feature#17472] HashWithIndifferentAccess like Hash extension — naruse@...

Issue #17472 has been reported by naruse (Yui NARUSE).

31 messages 2020/12/26

[#101710] [Ruby master Feature#17473] Make Pathname to embedded class of Ruby — hsbt@...

Issue #17473 has been reported by hsbt (Hiroshi SHIBATA).

28 messages 2020/12/26

[#101719] [Ruby master Feature#17474] Interpreting constants at compile time — jzakiya@...

Issue #17474 has been reported by jzakiya (Jabari Zakiya).

23 messages 2020/12/26

[#101735] [Ruby master Misc#17480] DevelopersMeeting20210113Japan — mame@...

Issue #17480 has been reported by mame (Yusuke Endoh).

12 messages 2020/12/27

[#101790] [Ruby master Bug#17486] Build fails on darwin due to libtool being removed — dark.panda@...

Issue #17486 has been reported by dark.panda (J Smith).

11 messages 2020/12/28

[#101794] [Ruby master Bug#17488] Regression in Ruby 3: Hash#key? is non-deterministic when argument uses DelegateClass — myron.marston@...

Issue #17488 has been reported by myronmarston (Myron Marston).

11 messages 2020/12/28

[#101809] [Ruby master Feature#17490] Rename RubyVM::MJIT to RubyVM::JIT — takashikkbn@...

Issue #17490 has been reported by k0kubun (Takashi Kokubun).

15 messages 2020/12/30

[#101838] [Ruby master Feature#17496] Add constant Math::TAU — jzakiya@...

Issue #17496 has been reported by jzakiya (Jabari Zakiya).

32 messages 2020/12/31

[#101840] [Ruby master Bug#17497] Ractor performance issue — marcandre-ruby-core@...

SXNzdWUgIzE3NDk3IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IG1hcmNhbmRyZSAoTWFyYy1BbmRyZSBM

21 messages 2020/12/31

[ruby-core:101375] [Ruby master Feature#16375] Right size regular expression compile buffers for literal regexes and on Regexp#freeze

From: mame@...
Date: 2020-12-10 09:23:55 UTC
List: ruby-core #101375
Issue #16375 has been updated by mame (Yusuke Endoh).

Status changed from Open to Closed

Merged by nobu at 9a17437558e42aa1da372b515ba8bc18067d578c

----------------------------------------
Feature #16375: Right size regular expression compile buffers for literal r=
egexes and on Regexp#freeze
https://bugs.ruby-lang.org/issues/16375#change-89134

* Author: methodmissing (Lourens Naud=E9)
* Status: Closed
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 3.0
----------------------------------------
References PR https://github.com/ruby/ruby/pull/2696

As a continuation of [type specific resize on freeze implementations of Str=
ing and Array](https://bugs.ruby-lang.org/issues/16291) and looking into th=
e `Regexp` type I found these memory access patterns for regular expression=
 literals:

```
=3D=3D22079=3D=3D -------------------- 12 of 500 --------------------
=3D=3D22079=3D=3D max-live:    1,946,560 in 4,345 blocks
=3D=3D22079=3D=3D tot-alloc:   1,946,560 in 4,345 blocks (avg size 448.00)
=3D=3D22079=3D=3D deaths:      none (none of these blocks were freed)
=3D=3D22079=3D=3D acc-ratios:  1.36 rd, 0.98 wr  (2,651,994 b-read, 1,908,1=
58 b-written)
=3D=3D22079=3D=3D    at 0x4C2DECF: malloc (in /usr/lib/valgrind/vgpreload_e=
xp-dhat-amd64-linux.so)
=3D=3D22079=3D=3D    by 0x24C496: onig_new_with_source (re.c:844)
=3D=3D22079=3D=3D    by 0x24C496: make_regexp (re.c:874)
=3D=3D22079=3D=3D    by 0x24C496: rb_reg_initialize (re.c:2858)
=3D=3D22079=3D=3D    by 0x24C496: rb_reg_initialize_str (re.c:2892)
=3D=3D22079=3D=3D    by 0x24C496: rb_reg_compile (re.c:2982)
=3D=3D22079=3D=3D    by 0x12EB84: rb_parser_reg_compile (parse.y:12185)
=3D=3D22079=3D=3D    by 0x12EB84: parser_reg_compile (parse.y:12179)
=3D=3D22079=3D=3D    by 0x12EB84: reg_compile (parse.y:12195)
=3D=3D22079=3D=3D    by 0x2147E3: new_regexp (parse.y:10101)
=3D=3D22079=3D=3D    by 0x2147E3: ruby_yyparse (parse.y:4419)
=3D=3D22079=3D=3D    by 0x2161F7: yycompile0 (parse.y:5942)
=3D=3D22079=3D=3D    by 0x3241FF: rb_suppress_tracing (vm_trace.c:427)
=3D=3D22079=3D=3D    by 0x1FDBF6: yycompile (parse.y:5991)
=3D=3D22079=3D=3D    by 0x1FDBF6: rb_parser_compile_file_path (parse.y:6130)
=3D=3D22079=3D=3D    by 0x27AC96: load_file_internal (ruby.c:2034)
=3D=3D22079=3D=3D    by 0x137730: rb_ensure (eval.c:1129)
=3D=3D22079=3D=3D    by 0x27CEEA: load_file (ruby.c:2153)
=3D=3D22079=3D=3D    by 0x27CEEA: rb_parser_load_file (ruby.c:2175)
=3D=3D22079=3D=3D    by 0x1954CE: load_iseq_eval (load.c:587)
=3D=3D22079=3D=3D    by 0x1954CE: rb_load_internal (load.c:651)
=3D=3D22079=3D=3D    by 0x1954CE: rb_f_load (load.c:709)
=3D=3D22079=3D=3D    by 0x2FB957: vm_call_cfunc_with_frame (vm_insnhelper.c=
:2468)
=3D=3D22079=3D=3D    by 0x2FB957: vm_call_cfunc (vm_insnhelper.c:2493)
```

Digging a little further and remembering some context of previous oniguruma=
 memory investigation I remembered the pattern buffer struct has a compile =
buffer with a simple watermark for tracking used space. This changeset impl=
ements `reg_resize` (static as `ary_resize`) which attempts to right size t=
he compile buffer if over allocated at the following sites:

* After compiling a literal regular expression.
* Implement an explicit type specific `rb_reg_freeze` and point `Regexp#com=
pile` to it
* I also follow the `chain` member which points to another `regex_t` on the=
 struct if present, but have not been able to find references to it in the =
source tree other than for freeing a regex or inspecting it's memory footpr=
int.

I introduced 2 new debug counters, which yields the following results on bo=
oting Redmine on Rails 5:

```
[RUBY_DEBUG_COUNTER]    obj_regexp_lit_extracapa                    6319
[RUBY_DEBUG_COUNTER]    obj_regexp_lit_extracapa_bytes            301685
```

About 300kb reallocated across 6319 oversized instances.

An example of `Regexp#freeze`

```
irb(main):007:0> r =3D Regexp.compile("(?!%\h\h|[!$-&(-;=3D?-_a-~]).")
irb(main):008:0> ObjectSpace.memsize_of(r)
=3D> 588
irb(main):009:0> r.freeze
=3D> /(?!%hh|[!$-&(-;=3D?-_a-~])./
irb(main):010:0> ObjectSpace.memsize_of(r)
=3D> 543
```

There is likely more layers that can be peeled back here, but keeping it si=
mple and concise for review.

I think it's possible to get towards a state where 5 to 10MB RSS can be sha=
ved off a standard Rails process by:

* Being careful with buffer defaults for objects that have auxiliary buffers
* Identifying hooks where excess allocation can be reduced to current water=
mark if the object buffer does not need to grow anymore (literal object, fr=
ozen object etc.)
* A GC hook on promotion to OLD object to trim excessive capacity, which I'=
d consider as a special kind of garbage, as outlined in https://bugs.ruby-l=
ang.org/issues/15402

Would any further incremental work towards this be considered worthwhile fr=
om a ruby-core and community perspective?



-- =

https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next