From: Joseph Jones Date: 2015-12-17T21:06:35-07:00 Subject: [ruby-core:72276] [Ruby trunk - Bug #11768] [Open] Add a polymorphic inline cache --5673864b_2d517796_16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Joseph Jones liked your message with Boxer. On December 3, 2015 at 12:25:= 16 MST, tenderlove=40ruby-lang.org wrote:Issue =2311768 has been reported= by Aaron Patterson.----------------------------------------Bug =2311768:= Add a polymorphic inline cachehttps://bugs.ruby-lang.org/issues/11768* A= uthor: Aaron Patterson* Status: Open* Priority: Normal* Assignee: Koichi = Sasada* ruby -v: * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN--= --------------------------------------Hi,I've attached a patch that adds = a PIC to the existing Mono IC struct.I haven't run every benchmark that's= checked in, but this patch speeds up the polymorphic call benchmark by a= bout 20%. Here is the benchmark *before* my patch:=7E=7E=7E=5Baaron=40TC = ruby (trunk)=5D=24 time ./ruby benchmark/bm=5Fvm2=5Fpoly=5Fmethod.rb real= 0m3.244suser 0m3.154ssys 0m0.044s=5Baaron=40TC ruby (trunk)=5D=24 time .= /ruby benchmark/bm=5Fvm2=5Fpoly=5Fmethod.rb real 0m3.158suser 0m3.090ssys= 0m0.042s=5Baaron=40TC ruby (trunk)=5D=24 time ./ruby benchmark/bm=5Fvm2=5F= poly=5Fmethod.rb real 0m3.162suser 0m3.099ssys 0m0.039s=7E=7E=7EHere it i= s with my patch applied:=7E=7E=7E=5Baaron=40TC ruby (pic2)=5D=24 time ./r= uby benchmark/bm=5Fvm2=5Fpoly=5Fmethod.rb real 0m2.522suser 0m2.455ssys 0= m0.044s=5Baaron=40TC ruby (pic2)=5D=24 time ./ruby benchmark/bm=5Fvm2=5Fp= oly=5Fmethod.rb real 0m2.515suser 0m2.458ssys 0m0.035s=5Baaron=40TC ruby = (pic2)=5D=24 time ./ruby benchmark/bm=5Fvm2=5Fpoly=5Fmethod.rb real 0m2.6= 37suser 0m2.545ssys 0m0.045s=7E=7E=7EMonomorhic call sites maintain the s= ame performance:Before:=7E=7E=7E=5Baaron=40TC ruby (trunk)=5D=24 time ./r= uby benchmark/bm=5Fvm2=5Fmethod.rb real 0m1.416suser 0m1.371ssys 0m0.032s= =5Baaron=40TC ruby (trunk)=5D=24 time ./ruby benchmark/bm=5Fvm2=5Fmethod.= rb real 0m1.456suser 0m1.402ssys 0m0.032s=5Baaron=40TC ruby (trunk)=5D=24= time ./ruby benchmark/bm=5Fvm2=5Fmethod.rb real 0m1.420suser 0m1.372ssys= 0m0.032s=7E=7E=7EAfter:=7E=7E=7E=5Baaron=40TC ruby (pic2)=5D=24 time ./r= uby benchmark/bm=5Fvm2=5Fmethod.rb real 0m1.451suser 0m1.399ssys 0m0.033s= =5Baaron=40TC ruby (pic2)=5D=24 time ./ruby benchmark/bm=5Fvm2=5Fmethod.r= b real 0m1.494suser 0m1.438ssys 0m0.033s=5Baaron=40TC ruby (pic2)=5D=24 t= ime ./ruby benchmark/bm=5Fvm2=5Fmethod.rb real 0m1.466suser 0m1.416ssys 0= m0.032s=7E=7E=7EThe down side of this patch is that it increases memory u= sage because the size of the call cache struct gets larger, even if the c= all site is monomorphic. I think we could make the code expand and contra= ct, but I'm not sure if it's worthwhile. The other downside is that it wi= ll probably slow down calls if the global method state changes, but I don= 't think that is a situation we should optimize for.I've actually attache= d 2 patches, one adds the PIC, the other adds a tracepoint so that I coul= d log cache hit / miss rates.---=46iles--------------------------------00= 01-add-PIC.patch (2.9 KB)0002-add-a-tracepoint-for-PIC-hit-miss.patch (4.= 33 KB)-- https://bugs.ruby-lang.org/ --5673864b_2d517796_16c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Joseph Jones liked your message with Boxer.


= On December 3, 2015 at 12:25:16 MST, tenderlove=40ruby-lang.org wrote:
Issue =2311768 has been = reported by Aaron Patterson.

---------------------------------= -------
Bug =2311768: Add a polymorphic inline cache
https://bu= gs.ruby-lang.org/issues/11768

* Author: Aaron Patterson
*= Status: Open
* Priority: Normal
* Assignee: Koichi Sasada
* ruby -v:
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN<= br />----------------------------------------
Hi,

I've at= tached a patch that adds a PIC to the existing Mono IC struct.

I haven't run every benchmark that's checked in, but this patch speeds u= p the polymorphic call benchmark by about 20%. Here is the benchmark *be= fore* my patch:

=7E=7E=7E
=5Baaron=40TC ruby (trunk)=5D=24= time ./ruby benchmark/bm=5Fvm2=5Fpoly=5Fmethod.rb

real 0m3.2= 44s
user 0m3.154s
sys 0m0.044s
=5Baaron=40TC ruby (trunk)=5D= =24 time ./ruby benchmark/bm=5Fvm2=5Fpoly=5Fmethod.rb

real 0m= 3.158s
user 0m3.090s
sys 0m0.042s
=5Baaron=40TC ruby (trun= k)=5D=24 time ./ruby benchmark/bm=5Fvm2=5Fpoly=5Fmethod.rb

re= al 0m3.162s
user 0m3.099s
sys 0m0.039s
=7E=7E=7E

Here it is with my patch applied:

=7E=7E=7E
=5Baaron=40= TC ruby (pic2)=5D=24 time ./ruby benchmark/bm=5Fvm2=5Fpoly=5Fmethod.rb
real 0m2.522s
user 0m2.455s
sys 0m0.044s
=5Baaro= n=40TC ruby (pic2)=5D=24 time ./ruby benchmark/bm=5Fvm2=5Fpoly=5Fmethod.r= b

real 0m2.515s
user 0m2.458s
sys 0m0.035s
=5B= aaron=40TC ruby (pic2)=5D=24 time ./ruby benchmark/bm=5Fvm2=5Fpoly=5Fmeth= od.rb

real 0m2.637s
user 0m2.545s
sys 0m0.045s
=7E=7E=7E

Monomorhic call sites maintain the same performance= :

Before:

=7E=7E=7E
=5Baaron=40TC ruby (trunk)= =5D=24 time ./ruby benchmark/bm=5Fvm2=5Fmethod.rb

real 0m1.41= 6s
user 0m1.371s
sys 0m0.032s
=5Baaron=40TC ruby (trunk)=5D= =24 time ./ruby benchmark/bm=5Fvm2=5Fmethod.rb

real 0m1.456s<= br />user 0m1.402s
sys 0m0.032s
=5Baaron=40TC ruby (trunk)=5D=24= time ./ruby benchmark/bm=5Fvm2=5Fmethod.rb

real 0m1.420s
user 0m1.372s
sys 0m0.032s
=7E=7E=7E

After:
<= br />=7E=7E=7E
=5Baaron=40TC ruby (pic2)=5D=24 time ./ruby benchmark= /bm=5Fvm2=5Fmethod.rb

real 0m1.451s
user 0m1.399s
s= ys 0m0.033s
=5Baaron=40TC ruby (pic2)=5D=24 time ./ruby benchmark/bm= =5Fvm2=5Fmethod.rb

real 0m1.494s
user 0m1.438s
sys = 0m0.033s
=5Baaron=40TC ruby (pic2)=5D=24 time ./ruby benchmark/bm=5F= vm2=5Fmethod.rb

real 0m1.466s
user 0m1.416s
sys 0m0= .032s
=7E=7E=7E

The down side of this patch is that it in= creases memory usage because the size of the call cache struct gets large= r, even if the call site is monomorphic. I think we could make the code = expand and contract, but I'm not sure if it's worthwhile. The other down= side is that it will probably slow down calls if the global method state = changes, but I don't think that is a situation we should optimize for.
I've actually attached 2 patches, one adds the PIC, the other ad= ds a tracepoint so that I could log cache hit / miss rates.

--= -=46iles--------------------------------
0001-add-PIC.patch (2.9 KB)=
0002-add-a-tracepoint-for-PIC-hit-miss.patch (4.33 KB)

<= br />--
https://bugs.ruby-lang.org/
<= /body> --5673864b_2d517796_16c--