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 collapse Modifiers into Builder object in TypedTag#apply #167

Closed lihaoyi closed 6 years ago

lihaoyi commented 7 years ago

Alternate diff to #166, but with a bit more micro-optimizations and cleanups after

As is the case in #166, 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 in "most" cases you would be fine saving a Tag in a val and re-using it over and over, possibly adding different sets of attributes or children to it. With this diff, you should no longer assign Frags or Tags to vals, as any children or attributes added will mutate the object and affect all over references to it. All Frags and Tags should be defs and re-computed each time they are needed.

My rudimentary benchmarks using

sbt ++2.12.2 "~scalatagsJS/test-only -- scalatags.jsdom.ScalatagsPerf.correctness.performance"

Appears to show about: