lightningcss icon indicating copy to clipboard operation
lightningcss copied to clipboard

Keep final semicolon in minified declaration blocks when targeting IE

Open vermiculus opened this issue 3 years ago • 3 comments

IE (not necessarily Edge, but definitely IE) parses CSS some 2-3% faster if there's a final newline in a declaration block, e.g.

.some-class{some-prop:some-value;other:value;}

Is this possible today with existing configuration? From looking at the code, I don't think so, but I'm not 100% sure I'm looking for the right stuff.

If it's not currently supported, is this the right section of the code to modify to be sensitive to the browser target here? (Specifically the conditional if i!= len -1 bit.) Would we want an additional field in MinifyOptions to prefer performance over file size / network transfer speed?

macro_rules! write {
  ($decls: expr, $important: literal) => {
    for decl in &$decls {
      decl.to_css(dest, $important)?;
      if i != len - 1 {
        dest.write_char(';')?;
        dest.whitespace()?;
      }
      i += 1;
    }
  };
}

vermiculus avatar Sep 27 '22 17:09 vermiculus

Do you have any more information about this performance issue?

devongovett avatar Sep 28 '22 01:09 devongovett

We maintain an extremely large web application and these numbers were gathered by internal performance experts, but the specific dev that owned the initial development is OOO right now at a career fair. Here's what I have from his notes, though:

As far as I can tell, removing that last semicolon to save one extra byte per CSS rule absolutely kills IE11. Expressed as a percentage, this is how much of an overall savings on response time was realized throughout my entire lab script for all four tested options:

Scenario Savings
Whitespace removal from libsass (leaves trailing semicolon) -2.7%
Removal of vendor-prefix rules -1.3%
Whitespace (leave semicolon), vendor, and rule deduplication -3.5%
Whitespace (all), vendor, and rule deduplication -1.9%

IE's engine must need to do a ton of extra work to deal with unterminated lines, at the cost of fully half of the performance improvement that these changes realize.

If there's specific measurements you'd like to see, I'll see what I can do to get them.

FYI I do have an in-progress patch at https://github.com/vermiculus/lightningcss/tree/sa/ie-perf to resolve this. The patch is working right now in dev; I just need to make it specific to targeting minification at IE.

vermiculus avatar Sep 28 '22 15:09 vermiculus

I've heard back from our dev who confirms we don't really have more details on exactly why performance suffered -- only that it did suffer when only changing whether or not terminal semicolons were used.

vermiculus avatar Sep 29 '22 15:09 vermiculus