0
0
SASSmarkup~8 mins

Functions vs mixins comparison in SASS - Performance Comparison

Choose your learning style9 modes available
Performance: Functions vs mixins comparison
MEDIUM IMPACT
This affects CSS generation size and browser rendering speed by controlling how styles are reused and output.
Reusing style code for multiple selectors
SASS
$shadow: 0 4px 6px rgba(0,0,0,0.1);
.button { box-shadow: $shadow; }
.card { box-shadow: $shadow; }
Using variables or functions outputs CSS once, reducing duplication and file size.
📈 Performance GainSmaller CSS bundle, faster LCP due to less CSS to parse
Reusing style code for multiple selectors
SASS
@mixin box-shadow() { box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.button { @include box-shadow(); }
.card { @include box-shadow(); }
Mixins duplicate CSS code each time they are included, increasing CSS file size and load time.
📉 Performance CostAdds repeated CSS rules, increasing bundle size and blocking rendering longer
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Using mixins for repeated stylesNo direct DOM impactNo direct reflows but larger CSS triggers slower style calculationHigher paint cost due to larger CSS[X] Bad
Using functions for value reuseNo direct DOM impactNo reflows triggeredLower paint cost with smaller CSS[OK] Good
Rendering Pipeline
Functions compute values at compile time, producing minimal CSS. Mixins inject full CSS blocks each use, increasing CSS size and parsing time.
Style Calculation
Layout
Paint
⚠️ BottleneckStyle Calculation due to larger CSS from mixins
Core Web Vital Affected
LCP
This affects CSS generation size and browser rendering speed by controlling how styles are reused and output.
Optimization Tips
1Use Sass functions to compute and reuse values without duplicating CSS.
2Avoid overusing mixins to prevent bloated CSS and slower page load.
3Check CSS bundle size and style recalculation time to optimize Sass usage.
Performance Quiz - 3 Questions
Test your performance knowledge
Which Sass feature helps reduce CSS file size by returning values instead of duplicating styles?
AMixins
BFunctions
CPlaceholders
DVariables
DevTools: Performance
How to check: Record page load and look at CSS parsing and style recalculation times; compare CSS file sizes in Network panel.
What to look for: Longer style recalculation or larger CSS files indicate inefficient mixin use; smaller CSS and faster style calculation indicate good function use.