com-lihaoyi / scalatags

ScalaTags is a small XML/HTML construction library for Scala.
https://com-lihaoyi.github.io/scalatags/
MIT License
758 stars 117 forks source link

DO NOT MERGE: eagerly stringifying tags when applied, rather than storing them up and stringifying on .render #166

Closed lihaoyi closed 6 years ago

lihaoyi commented 7 years ago

This makes Frags and Tags no longer immutable. They never really were, especially in JsDom land where they could contain arbitrary mutable DOM elements, but this would make it official. With this diff, you should no longer assign Frags or Tags to vals: they should be defs and re-computed each time.

text.Builder is now just a StringBuilder, and any Frags that get passed into a Tag get immediately flattened into that StringBuilder

This should build-up/tear-down fewer intermediate data-structures and result in less garbage/memory usage, but somehow still seems to be giving me a 10-20% slowdown rather than a speed-up. Notably, going "halfway" (commit 7dc316a) to make Frags directly affect the Builder but not get immediately flattened, seems to give about a 20% speedup. I've poked around with JProfiler and haven't figured out why putting things into a StringBuilder earlier rather than later is resulting in such a huge slowdown