@@ -10,15 +10,16 @@ kstyled transforms styles at compile time, resulting in zero runtime overhead co
1010
1111### Bundle size comparison
1212
13- | Library | Bundle Size (minified) | Packages Required |
14- | ---------| ----------------------| -------------------|
15- | ** kstyled** | ~ 10 KB | 1 package: ` kstyled ` |
16- | ** @emotion/native ** | ~ 13-18 KB | 3 packages: ` @emotion/native ` + ` @emotion/primitives-core ` + ` @emotion/react ` * |
17- | ** styled-components/native** | ~ 21 KB | 1 package: ` styled-components ` (includes both web & native) |
13+ | Library | Bundle Size (minified) | Packages Required |
14+ | ---------------------------- | ---------------------- | ------------------------------------------------------------------------------- |
15+ | ** kstyled** | ~ 10 KB | 1 package: ` kstyled ` |
16+ | ** @emotion/native ** | ~ 13-18 KB | 3 packages: ` @emotion/native ` + ` @emotion/primitives-core ` + ` @emotion/react ` \ * |
17+ | ** styled-components/native** | ~ 21 KB | 1 package: ` styled-components ` (includes both web & native) |
1818
19- * \* @emotion/react is a required peer dependency for @emotion/native to work *
19+ _ \* @emotion/react is a required peer dependency for @emotion/native to work _
2020
2121** Key insights:**
22+
2223- ** kstyled is the smallest** at ~ 10 KB with everything in one package
2324- ** @emotion/native requires 3 separate packages** totaling ~ 13-18 KB:
2425 - ` @emotion/native ` : ~ 1 KB (just a wrapper)
@@ -30,7 +31,7 @@ kstyled transforms styles at compile time, resulting in zero runtime overhead co
3031 - Includes both web and native in the same npm package
3132 - Use ` styled-components/native ` import path for React Native
3233
33- * Additional note: styled-components and emotion also depend on ` css-to-react-native ` (~ 25 KB) for runtime CSS parsing.*
34+ _ Additional note: styled-components and emotion also depend on ` css-to-react-native ` (~ 25 KB) for runtime CSS parsing._
3435
3536### Rendering performance
3637
@@ -62,7 +63,7 @@ const Item = styled(View)`
6263<FlatList
6364 data = { items }
6465 renderItem = { ({ item }) => <Item >{ item .content } </Item >}
65- />
66+ />;
6667```
6768
6869### Static-heavy components
@@ -110,13 +111,13 @@ const Button = styled(Pressable)<{ $primary?: boolean }>`
110111 padding: 12px 24px;
111112 border-radius: 8px;
112113 font-weight: 600;
113- background-color: ${p => p .$primary ? ' #007AFF' : ' #ccc' };
114+ background-color: ${( p ) => ( p .$primary ? ' #007AFF' : ' #ccc' ) };
114115` ;
115116
116117// Less optimal - everything dynamic
117118const Button = styled (Pressable )<{ $padding? : number ; $radius? : number }>`
118- padding: ${p => p .$padding || 12 }px;
119- border-radius: ${p => p .$radius || 8 }px;
119+ padding: ${( p ) => p .$padding || 12 }px;
120+ border-radius: ${( p ) => p .$radius || 8 }px;
120121` ;
121122```
122123
@@ -131,11 +132,7 @@ const Item = styled(View)`
131132` ;
132133
133134function MyItem({ color }: { color: string }) {
134- return (
135- <Item style = { { backgroundColor: color }} >
136- { /* ... */ }
137- </Item >
138- );
135+ return <Item style = { { backgroundColor: color }} >{ /* ... */ } </Item >;
139136}
140137```
141138
@@ -151,7 +148,7 @@ const getButtonColor = (variant: string) => {
151148
152149const Button = styled (Pressable )<{ $variant: string }>`
153150 padding: 12px;
154- background-color: ${p => getButtonColor (p .$variant )};
151+ background-color: ${( p ) => getButtonColor (p .$variant )};
155152` ;
156153
157154// Consider memoizing or pre-computing
@@ -193,13 +190,13 @@ Below are real benchmark results from our test app rendering 50 complex cards:
193190
194191</details >
195192
196- | Metric | kstyled | emotion |
197- | --------| ---------| ---------|
198- | ** Median** | ** 477.74ms** | ** 561.23ms** |
199- | Mean | 482.43ms | 565.34ms |
200- | Min / Max | 476.66ms / 494.44ms | 544.33ms / 592.24ms |
201- | P95 | 494.15ms | 585.37ms |
202- | Std Dev | ±7.55ms | ±12.32ms |
193+ | Metric | kstyled | emotion |
194+ | ---------- | ------------------- | ------------------- |
195+ | ** Median** | ** 477.74ms** | ** 561.23ms** |
196+ | Mean | 482.43ms | 565.34ms |
197+ | Min / Max | 476.66ms / 494.44ms | 544.33ms / 592.24ms |
198+ | P95 | 494.15ms | 585.37ms |
199+ | Std Dev | ±7.55ms | ±12.32ms |
203200
204201** Result: 14.9% faster** ⚡
205202
@@ -216,13 +213,13 @@ Below are real benchmark results from our test app rendering 50 complex cards:
216213
217214</details >
218215
219- | Metric | kstyled | styled-components |
220- | --------| ---------| -------------------|
221- | ** Median** | ** 182.94ms** | ** 199.47ms** |
222- | Mean | 186.21ms | 193.26ms |
223- | Min / Max | 182.37ms / 215.84ms | 182.33ms / 201.51ms |
224- | P95 | 201.20ms | 200.82ms |
225- | Std Dev | ±9.88ms | ±8.35ms |
216+ | Metric | kstyled | styled-components |
217+ | ---------- | ------------------- | ------------------- |
218+ | ** Median** | ** 182.94ms** | ** 199.47ms** |
219+ | Mean | 186.21ms | 193.26ms |
220+ | Min / Max | 182.37ms / 215.84ms | 182.33ms / 201.51ms |
221+ | P95 | 201.20ms | 200.82ms |
222+ | Std Dev | ±9.88ms | ±8.35ms |
226223
227224** Result: 8.3% faster** ⚡
228225
@@ -231,6 +228,7 @@ Below are real benchmark results from our test app rendering 50 complex cards:
231228</div >
232229
233230** Test configuration:**
231+
234232- 50 cards per benchmark
235233- 10 iterations per library (3 warm-up iterations discarded)
236234- Randomized order each iteration
@@ -247,17 +245,17 @@ The performance advantage comes from **build-time optimization**:
247245const Box = styled (View )`
248246 padding: 16px;
249247 border-radius: 12px;
250- background-color: ${p => p .$selected ? ' #007AFF' : ' #FFF' };
248+ background-color: ${( p ) => ( p .$selected ? ' #007AFF' : ' #FFF' ) };
251249` ;
252250
253251// Is compiled at build time to:
254252const styles = StyleSheet .create ({
255- s0: { padding: 16 , borderRadius: 12 }
253+ s0: { padding: 16 , borderRadius: 12 },
256254});
257255
258256const Box = (props ) => {
259257 const dynamicStyle = {
260- backgroundColor: props .$selected ? ' #007AFF' : ' #FFF'
258+ backgroundColor: props .$selected ? ' #007AFF' : ' #FFF' ,
261259 };
262260 return <View style = { [styles .s0 , dynamicStyle ]} { ... props } />;
263261};
@@ -274,10 +272,13 @@ const Box = (props) => {
274272### Performance characteristics
275273
276274The ** 8-15% improvement** is consistent across different types of components:
275+
277276- Components with mostly static styles benefit from build-time compilation
278277- Components with dynamic styles still benefit from faster component instantiation and lighter runtime overhead
279278- The improvement is most noticeable when rendering many components (e.g., long lists)
280279
280+ ** Note on real-world impact** : While our simple benchmark shows an 8-15% performance improvement, ** more complex components with deeper nesting, multiple dynamic props, and heavy style computations can see even larger performance gains** . The compile-time optimization becomes increasingly beneficial as component complexity grows, since kstyled eliminates all CSS parsing overhead regardless of style complexity.
281+
281282### Important notes
282283
283284- Both kstyled and runtime CSS-in-JS libraries are highly optimized
0 commit comments