On Thu, Dec 03, 2015 at 10:51:08PM +0000, Eric Wong wrote:
> tenderlove / ruby-lang.org wrote:
> > I haven't run every benchmark that's checked in, but this patch speeds
> > up the polymorphic call benchmark by about 20%.
> 
> Nice!
> 
> > The down side of this patch is that it increases memory usage because
> > the size of the call cache struct gets larger, 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.
> 
> Perhaps you can simplify the code so the existing monomorphic cache is
> just: POLYMORPHIC_CACHE_SIZE == 1

Yes, I'd love to do that.  The reason I didn't is because it looks like
there are a bunch of other places that allocate an rb_call_cache
directly and directly set the cached members.

I wanted to keep this patch as small as possible to a) figure out if we
want to do it (check benchmarks etc), and b) try to figure out what the
actual size should be.

If we do want to do this, then I'll go through and refactor the other
places so that we don't have the strange "one off" case.

> By the way, how did you arrive at the value of 6?

I started with 3 because I read somewhere (I think it was here:
http://chrisseaton.com/phd/specialising-ruby.pdf ) that 3 is good.  But
Charles Nutter told me they default the PIC on JRuby to 6, so I just
took it from them.

I'm not 100% confident in the best size, which is why I added the
tracepoint for logging.  With a size of 3, nearly all callsites had a
99% hit rate in the Psych tests.

> Memory usage is a bigger problem of Ruby than speed to me;
> so maybe a smaller value is a compromise.

I think a smaller value would be fine.  I can get some stats from
running the Rails tests and running our test suite at work.  Maybe that
would give us a better idea, though I think maybe 3 would be good
enough?

> > The other downside 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.
> 
> Agreed.  Did you measure startup performance?

No, I haven't measured startup performance.  I've run tests suites from
a few different projects and didn't notice any startup difference, but I
didn't test the time specifically.  Do you have any suggestions for how
to best do that?

-- 
Aaron Patterson
http://tenderlovemaking.com/