Re: [cssom] Make CSSStyleSheet constructable

On Wed, Oct 17, 2012 at 5:33 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> On 10/17/12 8:16 PM, Tab Atkins Jr. wrote:
>> The "scoping" nature of a TreeScope is good for preventing stray
>> styles from leaking out of the component, but it's problematic when
>> you have, say, a thousand copies of the same component on the page,
>> all of which contain their own, identical, copies of the same
>> stylesheet.
>
> This is an inline stylesheet, not a linked stylesheet?

Generally, both.


>> Our attempts to date have been somewhat hacky, unfortunately.
>
> I'm not sure why.  Gecko already does such sharing on the style data of
> linked stylesheets.  It would be easy to extend it to inline stylesheets if
> needed.

Copy-on-write semantics for style sharing is totally doable, don't get
me wrong.  However, for this case (sharing among components) we feel
it has the wrong ergonomics.

I'll explain.  Normally, if you happen to share the same stylesheet
across multiple documents, the docs are all fairly independent.  (This
is my assumption, at least.)  This means that, if one doc does some
CSSOM manipulation of the stylesheet, thus forcing a copy, it's not
generally likely that the rest of the docs will do the same.

Components are likely to be different.  Since they all run identical
script, if any one instance of a component does some CSSOM
manipulation, it's likely that they *all* will.  Thus, we feel that
simply relying on copy-on-write optimizations will lead to a bad place
where performance is normally great, but one small tweak to your
scripts will throw it in the toilet as you suddenly generate a
thousand separate stylesheets on production pages.  We also feel that
it's unlikely that this will show up in normal developer testing, as
few devs will stress-test with thousands of instances, while that kind
of thing will be reasonably common for certain types of components in
production (+1 buttons, etc.).

So, an explicit sharing mechanism that doesn't have an implicit
failure mode feels like the right direction to aim for, in our minds.

~TJ

Received on Friday, 19 October 2012 17:48:38 UTC