Skip to content

Commit cde9a69

Browse files
authored
Merge pull request #2286 from gluestack/feat/benchmarks-v2
feat/benchmarks v2
2 parents eeedb82 + 69149a2 commit cde9a69

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed

example/storybook-nativewind/.storybook/preview.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export const parameters = {
4646
],
4747
'Core Concepts',
4848
['Accessibility', 'Universal'],
49+
'Performance',
50+
['Benchmarks'],
4951
'Theme Configuration',
5052
['Default Tokens', 'Customizing Theme', 'Dark Mode'],
5153
],
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { Text, HStack, VStack, Box } from '@gluestack-ui/themed';
2+
import React from 'react';
3+
4+
export function Graph({ data }: { data: any }) {
5+
const colorMap: any = {
6+
'gluestack-ui v1': '#0077E6',
7+
'React Native': '#61dafb',
8+
'gluestack-ui v2': '#eab308',
9+
};
10+
11+
const maxValue = Math.max(...Object.values(data).map((stat: any) => stat));
12+
13+
return (
14+
<VStack
15+
space="sm"
16+
pl="$12"
17+
pr="$4"
18+
py="$12"
19+
bg="#fbfbfb"
20+
rounded="$md"
21+
sx={{
22+
_dark: {
23+
bg: '$backgroundDark800',
24+
},
25+
}}
26+
mb="$8"
27+
>
28+
{Object.keys(data).map((key) => {
29+
const width = `${Math.round((data[key] / maxValue) * 100)}%`;
30+
31+
return (
32+
<HStack w="$full" space="md" alignItems="center">
33+
<VStack>
34+
<Text
35+
sx={{
36+
color: '$text900',
37+
_dark: {
38+
color: '$text50',
39+
},
40+
_web: { whiteSpace: 'nowrap' },
41+
w: 130,
42+
fontSize: '$sm',
43+
textAlign: 'right',
44+
fontWeight: key === 'gluestack-ui' ? '$semibold' : '$normal',
45+
}}
46+
>
47+
{key}
48+
</Text>
49+
</VStack>
50+
<HStack space="md" alignItems="center" flex={0.7}>
51+
<Box
52+
h={'$5'}
53+
w={width}
54+
borderRadius={'$sm'}
55+
bgColor={colorMap[key] ?? '$primary500'}
56+
/>
57+
<Text
58+
fontSize="$xs"
59+
flex={1}
60+
sx={{
61+
color: '$text900',
62+
_dark: {
63+
color: '$text50',
64+
},
65+
_web: {
66+
whiteSpace: 'nowrap',
67+
},
68+
}}
69+
>
70+
{data[key]} ms
71+
</Text>
72+
</HStack>
73+
</HStack>
74+
);
75+
})}
76+
</VStack>
77+
);
78+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Performance Benchmarks | gluestack-ui
3+
description: gluestack-ui harnesses the power of NativeWind, a universal and highly performant styling library, to style the components.
4+
---
5+
6+
import { Canvas, Meta, Story } from '@storybook/addon-docs';
7+
import { Graph } from '../../../extra-components/nativewind/Progress';
8+
9+
<Meta title="ui/Home/Performance/Benchmarks" />
10+
11+
# Performance Benchmarks
12+
13+
`gluestack-ui` harnesses the power of [NativeWind](https://www.nativewind.dev/v4/overview), a universal and highly performant styling library, to style the components.
14+
15+
# React Native
16+
17+
We performed the [benchmarks](https://github.com/gluestack/gluestack-ui-benchmarks) with `React Native`, `gluestack-ui v1` and `gluestack-ui v2`.
18+
19+
**In each case we have rendered 1000 components with styling of each library. Results are average of 5 mounts.**
20+
21+
> **All the benchmarks were measured in production environment on iPhone 15.**
22+
23+
## Simple Component
24+
25+
The time it takes to render a simple themed component. We've developed a Box component using View with some default styles.
26+
27+
<Graph
28+
data={{
29+
'React Native': 68,
30+
'gluestack-ui v1': 132,
31+
'gluestack-ui v2': 99,
32+
}}
33+
/>
34+
35+
## Component with variants
36+
37+
The time needed to render a component with different variations. We've developed a Box component using View with default styles and multiple variants.
38+
39+
<Graph
40+
data={{
41+
'React Native': 73,
42+
'gluestack-ui v1': 146,
43+
'gluestack-ui v2': 144,
44+
}}
45+
/>
46+
47+
> Styled Components doesn't have built-in support for variants. We've incorporated prop-based variants into Styled Components.
48+
49+
## Component with default theme and inline styles
50+
51+
A component with default themes, variations, inline styles, and state styles. We've designed a Button component using Pressable with default style, variations, state style, and inline styles.
52+
53+
<Graph
54+
data={{
55+
'gluestack-ui v1': 360,
56+
'gluestack-ui v2': 241,
57+
}}
58+
/>
59+
60+
> React Native doesn't provide out of the box support for state styling.
61+
62+
## Layout using HStack, VStack, Image and Text
63+
64+
Creating a layout with HStack, VStack, Image, and Text to display a list of 28 items. We've utilized components from the following libraries for this purpose.
65+
66+
<Graph
67+
data={{
68+
'React Native': 58,
69+
'gluestack-ui v1': 89,
70+
'gluestack-ui v2': 76,
71+
}}
72+
/>
73+
74+
> Note: This test was taken from [Tamagui](https://github.com/tamagui/tamagui/tree/24ac758bbe5d6ff2f67f25071df4286e0594f578/starters/benchmark).
75+
76+
# Web
77+
78+
We are working on dedicated benchmarks for the web. Stay tuned for more updates!
79+
80+
In the meantime, we've built the landing page for version 2 using `gluestack-ui v2`, achieving a Lighthouse score of 85+.

0 commit comments

Comments
 (0)