Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
polymorphic vs monomorphic #9
Jakob Kummerow wrote:
The higher the degree of polymorphism, the bigger the performance cost. For two different shapes, I'm seeing about 10-30% more time in the polymorphic compared to the monomorphic version; for four different shapes the delta goes up to 60-100% (it's pretty flaky in repeated runs).
Note that all these numbers are very specific to the situation you're testing. If you swap the order of properties in the object -- it makes a difference. If some of the object shapes show up more frequently than others -- it makes a difference. For polymorphism degrees greater than four, even what the rest of your program is doing makes a (possibly huge!) difference. It's extremely difficult to draw simple, generally-true conclusions from this, or give general advice. Polymorphism can be anything from "nothing to worry about" to "the single biggest performance problem with this app".