styleForRenderer() is a pretty heavy function. In some cases we compute it twice in "Element::recalcStyle" and "NodeRendererFactory::createRendererIfNeeded". NdeRendererFactory is called via Element::attach
I have attached a file where this improvement does improve the performance of Element::recalc. For the attached file, the improvement is on the order of 3-4us. On measurements on a reasonably complex page, doing the caching results in a .1 - .5ms improvement in processing Element::recalc
I'm planning to get rid of NodeRenderingFactory class which just confuses things. Computing the style twice in case of attach() triggered from recalcStyle is indeed a problem that should be fixed.
Created attachment 122784 [details]
I did a bit more measurements. For a reasonable web site, for a page where the recalc is done twice, this produces a performance improvement in Element::recalcStyle of about 1%