Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Combining style tags into a single style tag helps performance #1392

Open
irfantusneem opened this issue Aug 26, 2014 · 1 comment
Open

Combining style tags into a single style tag helps performance #1392

irfantusneem opened this issue Aug 26, 2014 · 1 comment
Milestone

Comments

@irfantusneem
Copy link

Combining style tags into a single style tag helps performance. The code below is a change to shadow_dom_component_factory.dart to cache the combined style tags for a component so only a single tag is output.

Ran the code against 10,000 instances of a button list component 5 times and it showed a 3% performance improvement.

The code below is a bit of a hack since it assumes there are only 2 styles but it can be cleaned up to handle more.

            // ############NEW CODE DOWN##################
  static Map _twoListMap = {};
            // ############NEW CODE UP##################
  Function call(dom.Element element) {
    return (DirectiveInjector injector, Scope scope, NgBaseCss baseCss,
            EventHandler _) {
      var s = traceEnter(View_createComponent);
      try {
        var shadowDom = element.createShadowRoot()
          ..applyAuthorStyles = _component.applyAuthorStyles
          ..resetStyleInheritance = _component.resetStyleInheritance;

        var shadowScope = scope.createChild(new HashMap()); // Isolate

        async.Future<Iterable<dom.StyleElement>> cssFuture;
        if (_component.useNgBaseCss == true) {
          cssFuture = async.Future.wait([async.Future.wait(baseCss.urls.map(_styleFuture)), _styleElementsFuture]).then((twoLists) {
            assert(twoLists.length == 2);
            var cssList = []..addAll(twoLists[0])
            ..addAll(twoLists[1]);
            // ############NEW CODE DOWN##################
            var css1 = cssList[0];
            var css2 = cssList[1];
            var styleMap = _twoListMap[css1];
            if (styleMap == null) {
              styleMap = new Map();
              _twoListMap[css1] = styleMap;
            }
            var styleDom = styleMap[css2];
            if (styleDom == null) {
              styleDom = new dom.StyleElement()..appendText(css1.text + css2.text);
              styleDom = [ styleDom ];
              styleMap[css2] = styleDom;
            }
            return styleDom;
            // ############NEW CODE  UP##################
            // return cssList;
          });
        } else {
          cssFuture = _styleElementsFuture;
        }
@mhevery
Copy link
Contributor

mhevery commented Oct 2, 2014

will be addressed in the new compiler.

@naomiblack naomiblack modified the milestones: post v1.0, v1.0 Oct 3, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants