linkedin / css-blocks

High performance, maintainable stylesheets.
http://css-blocks.com/
BSD 2-Clause "Simplified" License
6.33k stars 152 forks source link

Simplify Dynamic Attribute Rewrite #473

Closed chriseppstein closed 3 years ago

chriseppstein commented 3 years ago

This change greatly simplifies the per-element rewrite for elements that have dynamic attribute values. In the element rewrite we no longer enumerate all the attribute values as possible styles and we don't enumerate the specific values as part of the switch condition. Instead we just reference the attribute as being a switch condition and let the runtime fill in the possible values from new information that is passed in for the aggregate rewrite data.

The aggregate rewrite data is more explicit than it strictly needs to be, the rewrite code could do some sort of string manipulation in order to construct the attribute value style name instead of looking it up in a table. However that solution would preclude a later optimization where we optimize away the strings and replace them with unique numbers.

In production code this change reduces the rewrite significantly (by more than 30 arguments in one element I examined) and should produce a significant savings in aggregate by avoiding duplication when the same attributes are used dynamically on different template elements throughout the application.

TODO: