Currently, you can re-use the same Tag or Frag objects, add more attributes and children, and re-render them multiple times. This means Tags and Frags are all immutable and nice and principled and stuff.
In practice, this doesn't happen that often, and doesn't really work with the JsDom backend anyway: with JsDom you can insert mutable dom.Element references into your Tags and Frags, and re-rendering the same Frag multiple times may misbehave since a dom.Element can only have a single position in the DOM.
As a result most of my Tags and Frags are one-shot values: rendered once and that's it.
We should be able to take advantage of the one-shot-ness: by performing the rendering immediately upon construction, we can save the cost of building a large, immutable Frag-tree just to throw it away. There may be some additional limitations (e.g. all for the Text backend Attrs may have to be applied before any child Frags, and all Cls would have to be applied consecutively) but overall it should be possible to make this work.
This should be able to give us a decent speedup in both JsDom and Text backends, on both Scala-JVM and Scala.js, which would then let me care even less about the performance of my Scalatags rendering code. Right now, I still have to be careful about e.g. rendering large templates during on-scroll handlers, but if it rendering was 2-3x faster I could maybe get by without caring at all.
Currently, you can re-use the same
Tag
orFrag
objects, add more attributes and children, and re-render them multiple times. This meansTag
s andFrag
s are all immutable and nice and principled and stuff.In practice, this doesn't happen that often, and doesn't really work with the
JsDom
backend anyway: withJsDom
you can insert mutabledom.Element
references into yourTag
s andFrag
s, and re-rendering the sameFrag
multiple times may misbehave since adom.Element
can only have a single position in the DOM.As a result most of my
Tag
s andFrag
s are one-shot values: rendered once and that's it.We should be able to take advantage of the one-shot-ness: by performing the rendering immediately upon construction, we can save the cost of building a large, immutable
Frag
-tree just to throw it away. There may be some additional limitations (e.g. all for theText
backendAttr
s may have to be applied before any childFrag
s, and allCls
would have to be applied consecutively) but overall it should be possible to make this work.This should be able to give us a decent speedup in both
JsDom
andText
backends, on both Scala-JVM and Scala.js, which would then let me care even less about the performance of my Scalatags rendering code. Right now, I still have to be careful about e.g. rendering large templates during on-scroll handlers, but if it rendering was 2-3x faster I could maybe get by without caring at all.