
What's up with monomorphism? - luu
http://mrale.ph/blog/2015/01/11/whats-up-with-monomorphism.html
======
pickpuck
Keep the comics!

------
bascule
Java HotSpot can inline both possibilities for bimorphic call sites. If this
is really an issue I'm surprised V8 doesn't have a similar functionality.

~~~
kannanvijayan
As a point of reference, SpiderMonkey does do this with its Ion jit (I
implemented some of the early polymorphic inlining code for Ion, but it's been
cleaned up and robustified greatly since then by different contributors).
We'll inline up to 4 callees at a site.

Aside: That was a very thorough and well written blog post, mraleph :) A very
enjoyable read.

edit - I do think the blog post implies that v8 can't do polymorphic inlining.
That's the impression I got from it anyway (and I was somewhat surprised, as I
had assumed it would). It may be worthwhile to change the wording to make it
more clear that V8 can inline more than one callee at a site.

~~~
mraleph
> I do think the blog post implies that v8 can't do polymorphic inlining.

It took me a bit to realize where this confusion comes from (especially given
the whole discussion of how polymorphic property access is handled). Is it due
to "Undiscussed - Not all caches are the same" section?

Indeed V8 can't at the moment do polymorphic inlining at non-method callsites
- f(), however it can on method callsites o.m().

The reason for this is lack of type feedback.

I will seek to clarify the wording in that section.

> Aside: That was a very thorough and well written blog post, mraleph :) A
> very enjoyable read.

Thanks.

~~~
kannanvijayan
Well, if you extend the call ICs to record multiple callees at the site, I'm
assuming it would be pretty straightforward to do this for all calls.

Not sure if it's worth the effort, though.

I think most of the reason SM has polymorphic inlining for all callsites is
that we added it first as a stop-gap for methodcall inlining, and then later
went back and added support for method callsites (guarding directly on the
receiver object's type and eliding the property lookup - which I assume is
what V8 did from the start).

If you already have methodcall polymorphic inlining, the return on investment
in expanding that to all callsites is perhaps pretty low.

Would be interesting to measure though..

~~~
mraleph
I have amended the section, please check it out.

There is certain technical heritage here.

Originally method calls compiled down to a single IC that did load and call
within a IC stub. Type feedback from these ICs was interpreted in the same way
as from property load ICs. On the other hand function calls cb(...) compiled
down to a call through CallFunctionStub which did not record any feedback
whatsoever. At some point CallFunctionStub learned to record a bit of type
feedback (monomorphic / megamorphic) and we started using it in Crankshaft for
speculative inlining.

Only recently method calls were decomposed into Load IC and a separate Call IC
(an evolved CallFunctionStub) which invokes loaded function. For property
invocation o.m(...) feedback comes from the Load IC now, and Call IC feedback
is ignored. For variable invocation cb(...) feedback comes from the Call IC -
which is still only able to distinguish only monomorphic and megamorphic
state.

~~~
kannanvijayan
Ah, makes sense. I just read through the updated post (took me a bit to find
the updated text), and it does clear up the methodcall polymorphism bit.

------
jokoon
is it true that javascript was designed in 10 days ?

~~~
mmastrac
Yep, but you have to keep in mind that it was inspired by years of exposures
to other languages.

[http://www.computer.org/csdl/mags/co/2012/02/mco2012020007-a...](http://www.computer.org/csdl/mags/co/2012/02/mco2012020007-abs.html)

