0

Ignoring, for a moment, the (important!) difference in functionality between an !important and a non-!important declaration within a CSS ruleset, which is more efficient in terms of memory use?


EDIT: Simone Rossaini posted a link to Is !important bad for performance?, which likely answers the performance implications (thank you Simone!), but I am more interested in the memory implications at this time.

  • 1
    Does this answer your question? [Is !important bad for performance?](https://stackoverflow.com/questions/13743671/is-important-bad-for-performance) – Simone Rossaini Jul 06 '20 at 13:21
  • @SimoneRossaini Thank you Simone! I just read some of the answers there, and I need to read the rest and study them all further. On initial inspection, they seem to indicate that there *might* be a slight performance degradation, but it should be minimal. I don't see any mention of memory use, however. – RockPaperLz- Mask it or Casket Jul 06 '20 at 13:34
  • You are welcome, i think it is quite obvious that the more direct the structure, the less memory and speed will be used. for example if I have a div with a class, and then I have a style together with! important it is natural that the steps are 'duplicated' – Simone Rossaini Jul 06 '20 at 13:36
  • @SimoneRossaini On the other hand, when an !important declaration overrides *multiple* other declarations, the browser does not need to deal with all those other declarations nor determine specificity for them. – RockPaperLz- Mask it or Casket Jul 06 '20 at 13:39
  • 1
    As with most performance issues, the most accurate information for your specific circumstances is going to be tests with your specific code. Run the code without `!important` take a snapshot of the memory usage. Run the code with `!important`, take a snapshot of the memory usage. Compare. – Heretic Monkey Jul 06 '20 at 13:47
  • @HereticMonkey How do you recommend taking a snapshot of memory usage? Memory fluctuations are typical in a normal operating environment. How do I isolate to get a valid result? – RockPaperLz- Mask it or Casket Jul 06 '20 at 13:53
  • Chrome has a memory profiler built into its Developer Tools with a profiling type called "Heap snapshot". Presumably some people find it helpful enough, even with these fluctuations. Isolation is a matter of repetition and data analysis, perhaps using different profiling types. – Heretic Monkey Jul 06 '20 at 13:59

0 Answers0