Issue #16245 has been updated by methodmissing (Lourens Naud=E9).


sam.saffron (Sam Saffron) wrote:
> Koichi introduced an experimental gem: https://github.com/ko1/iseq_collec=
tor
> =

> It allows:
> =

> ObjectSpace.each_iseq{|iseq| ...}
> ObjectSpace.count_iseq #=3D> Integer
> ObjectSpace.memsize_of_all_iseq (should not generate RubyVM::InstructionS=
equence wrappers for IMEMOs)
> =

> Since the wrapper object  RubyVM::InstructionSequence is lazily allocated=
, ObjectSpace.each_object does not find these IMEMOs unless they have been =
wrapped. This design is good and conserves memory. =

> =

> `count_iseq` and `memsize_of_all_iseq` are very powerful metrics most lar=
ge Ruby deployments can use to automatically detect method leaks introduced=
 via meta programming. These issues are invisible now short of walking a he=
ap dump. =

> =

> Can we add the new interface into 2.7?

I worked on `imemo_memsize` some time ago to correctly reflect the type siz=
es in https://github.com/ruby/ruby/commit/90c4bd2d2bd10b19c2b09834396553742=
bc7e8a4 which makes heap dumps more accurate. I understand the API proposal=
, but also I believe the intention was for these objects to be internal and=
 not necessarily to be exposed through API. However I do suspect for large =
Rails applications their combined footprint can add up, especially for the =
types that can allocate heap memory too:

* imemo_ment (method entries)
* imemo_iseq (as per your description above)
* imemo_env (bindings)
* imemo_tmpbuf (tried to support these on the transient heap but found them=
 to be almost never used much in practice as it appears to be a fallback fo=
r `ALLOCA` under some circumstances.
* imemo_ast

I have not had any free time to investigate further, but I think this is an=
 interesting storage class to explore further and I'd be interesting in hel=
ping, whichever way the proposal goes.

----------------------------------------
Feature #16245: Add interfaces to count and measure size all IMEMO objects
https://bugs.ruby-lang.org/issues/16245#change-81948

* Author: sam.saffron (Sam Saffron)
* Status: Open
* Priority: Normal
* Assignee: =

* Target version: =

----------------------------------------
Koichi introduced an experimental gem: https://github.com/ko1/iseq_collector

It allows:

ObjectSpace.each_iseq{|iseq| ...}
ObjectSpace.count_iseq #=3D> Integer
ObjectSpace.memsize_of_all_iseq (should not generate RubyVM::InstructionSeq=
uence wrappers for IMEMOs)

Since the wrapper object  RubyVM::InstructionSequence is lazily allocated, =
ObjectSpace.each_object does not find these IMEMOs unless they have been wr=
apped. This design is good and conserves memory. =


`count_iseq` and `memsize_of_all_iseq` are very powerful metrics most large=
 Ruby deployments can use to automatically detect method leaks introduced v=
ia meta programming. These issues are invisible now short of walking a heap=
 dump. =


Can we add the new interface into 2.7?



-- =

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>