Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit f209652

Browse files
authored
perf: add base perf examples (#2164)
* chore: sort yarn perf table * perf: add base perf examples * refactor: base perf to minimal perf * fix: typo * revert CSF, it breaks maximized view, screener, and codesandbox * fix tooltip minimal example
1 parent 0bdfb57 commit f209652

File tree

71 files changed

+543
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+543
-110
lines changed

build/gulp/tasks/perf.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,13 @@ const createMarkdownTable = (
9999

100100
return markdownTable([
101101
['Example', ...fieldLabels],
102-
..._.map(exampleMeasures, (exampleMeasure, exampleName) => [
103-
exampleName,
104-
...fieldValues[exampleName],
105-
]),
102+
..._.sortBy(
103+
_.map(exampleMeasures, (exampleMeasure, exampleName) => [
104+
exampleName,
105+
...fieldValues[exampleName],
106+
]),
107+
row => -row[fields.indexOf('median')],
108+
),
106109
])
107110
}
108111

docs/src/components/ComponentDoc/ComponentExample/ComponentExample.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,13 @@ class ComponentExample extends React.Component<ComponentExampleProps, ComponentE
429429

430430
render() {
431431
const {
432-
component,
433432
children,
434433
currentCode,
435434
currentCodeLanguage,
436435
currentCodePath,
437436
error,
438437
description,
438+
defaultExport,
439439
onError,
440440
title,
441441
wasCodeChanged,
@@ -519,7 +519,7 @@ class ComponentExample extends React.Component<ComponentExampleProps, ComponentE
519519
resolver={importResolver}
520520
/>
521521
) : (
522-
React.createElement(component)
522+
React.createElement(defaultExport)
523523
)}
524524
</VariableResolver>
525525
</Provider>

docs/src/components/ComponentDoc/ComponentSourceManager/ComponentSourceManager.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import * as React from 'react'
44

55
import { ExampleSource } from 'docs/src/types'
66
import { componentAPIs as APIdefinitions, ComponentAPIs } from './componentAPIs'
7-
import getExampleModule from './getExampeSource'
7+
import getExampleModule from './getExampeModule'
88

99
export type ComponentSourceManagerRenderProps = ComponentSourceManagerState & {
10-
component: React.ElementType
10+
defaultExport: React.ElementType
11+
namedExports: { [key: string]: React.ElementType }
1112
handleCodeAPIChange: (newApi: keyof ComponentAPIs) => void
1213
handleCodeChange: (newCode: string) => void
1314
handleCodeFormat: () => void
@@ -23,7 +24,8 @@ export type ComponentSourceManagerProps = {
2324
}
2425

2526
type ComponentSourceManagerAPIs = ComponentAPIs<{
26-
component: React.ElementType
27+
defaultExport: React.ElementType
28+
namedExports: { [key: string]: React.ElementType }
2729
sourceCode: ExampleSource | undefined
2830
supported: boolean
2931
}>
@@ -54,7 +56,8 @@ export default class ComponentSourceManager extends React.Component<
5456

5557
return {
5658
...definition,
57-
component: module && module.component,
59+
defaultExport: module && module.defaultExport,
60+
namedExports: module && module.namedExports,
5861
sourceCode: module ? module.source : '',
5962
supported: !!module,
6063
}
@@ -139,7 +142,8 @@ export default class ComponentSourceManager extends React.Component<
139142
render() {
140143
return this.props.children({
141144
...this.state,
142-
component: this.state.componentAPIs[this.state.currentCodeAPI].component,
145+
defaultExport: this.state.componentAPIs[this.state.currentCodeAPI].defaultExport,
146+
namedExports: this.state.componentAPIs[this.state.currentCodeAPI].namedExports,
143147
handleCodeAPIChange: this.handleCodeAPIChange,
144148
handleCodeChange: this.handleCodeChange,
145149
handleCodeFormat: this.handleCodeFormat,

docs/src/components/ComponentDoc/ComponentSourceManager/getExampeSource.ts renamed to docs/src/components/ComponentDoc/ComponentSourceManager/getExampeModule.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@ import { componentAPIs, ComponentAPIs } from './componentAPIs'
77
const getExampleModule = (
88
examplePath: string,
99
componentAPI: keyof ComponentAPIs,
10-
): { component: React.ElementType; source: ExampleSource } | undefined => {
10+
):
11+
| {
12+
defaultExport: React.ElementType
13+
namedExports: { [key: string]: React.ElementType }
14+
source: ExampleSource
15+
}
16+
| undefined => {
1117
const fileSuffix = componentAPIs[componentAPI].fileSuffix
1218

1319
const sourcePath = `${examplePath.replace(/^components/, '.')}${fileSuffix}.source.json`
1420
const modulePath = `./${examplePath}${fileSuffix}.tsx`
1521

1622
try {
1723
return {
18-
component: examplesContext(modulePath).default,
24+
defaultExport: examplesContext(modulePath).default,
25+
namedExports: examplesContext(modulePath),
1926
source: exampleSourcesContext(sourcePath),
2027
}
2128
} catch (e) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Accordion } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const AccordionMinimalPerf = () => <Accordion />
5+
6+
AccordionMinimalPerf.iterations = 5000
7+
AccordionMinimalPerf.filename = 'AccordionMinimal.perf.tsx'
8+
9+
export default AccordionMinimalPerf
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Alert } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const AlertMinimalPerf = () => <Alert />
5+
6+
AlertMinimalPerf.iterations = 5000
7+
AlertMinimalPerf.filename = 'AlertMinimal.perf.tsx'
8+
9+
export default AlertMinimalPerf
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Animation } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const AnimationMinimalPerf = () => <Animation />
5+
6+
AnimationMinimalPerf.iterations = 5000
7+
AnimationMinimalPerf.filename = 'AnimationMinimal.perf.tsx'
8+
9+
export default AnimationMinimalPerf

docs/src/examples/components/Attachment/Performance/Attachment.perf.tsx

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Attachment } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const AttachmentMinimalPerf = () => <Attachment />
5+
6+
AttachmentMinimalPerf.iterations = 5000
7+
AttachmentMinimalPerf.filename = 'AttachmentMinimal.perf.tsx'
8+
9+
export default AttachmentMinimalPerf
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Attachment } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const AttachmentSlotsPerf = () => (
5+
<Attachment
6+
actionable
7+
icon="table"
8+
header="Document.docx"
9+
description="800 Kb"
10+
action={{ icon: 'more', title: 'More Action' }}
11+
progress={33}
12+
/>
13+
)
14+
15+
AttachmentSlotsPerf.iterations = 5000
16+
AttachmentSlotsPerf.filename = 'AttachmentSlots.perf.tsx'
17+
18+
export default AttachmentSlotsPerf
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Avatar } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const AvatarMinimalPerf = () => <Avatar />
5+
6+
AvatarMinimalPerf.iterations = 5000
7+
AvatarMinimalPerf.filename = 'AvatarMinimal.perf.tsx'
8+
9+
export default AvatarMinimalPerf
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Box } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const BoxMinimalPerf = () => <Box />
5+
6+
BoxMinimalPerf.iterations = 5000
7+
BoxMinimalPerf.filename = 'BoxMinimal.perf.tsx'
8+
9+
export default BoxMinimalPerf

docs/src/examples/components/Button/Performance/Button.perf.tsx

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Button } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const ButtonMinimalPerf = () => <Button />
5+
6+
ButtonMinimalPerf.iterations = 5000
7+
ButtonMinimalPerf.filename = 'ButtonMinimal.perf.tsx'
8+
9+
export default ButtonMinimalPerf
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Button } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const ButtonSlotsPerf = () => (
5+
<Button
6+
icon="play"
7+
content="Click here"
8+
loader={{
9+
delay: 200,
10+
inline: true,
11+
label: 'Loading',
12+
labelPosition: 'end',
13+
size: 'smallest',
14+
}}
15+
/>
16+
)
17+
18+
ButtonSlotsPerf.iterations = 5000
19+
ButtonSlotsPerf.filename = 'ButtonSlots.perf.tsx'
20+
21+
export default ButtonSlotsPerf

docs/src/examples/components/Button/Performance/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const Performance = () => (
88
<ComponentPerfExample
99
title="Default"
1010
description="A default test."
11-
examplePath="components/Button/Performance/Button.perf"
11+
examplePath="components/Button/Performance/ButtonSlots.perf"
1212
/>
1313
</NonPublicSection>
1414
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Carousel } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const CarouselMinimalPerf = () => <Carousel />
5+
6+
CarouselMinimalPerf.iterations = 5000
7+
CarouselMinimalPerf.filename = 'CarouselMinimal.perf.tsx'
8+
9+
export default CarouselMinimalPerf

docs/src/examples/components/Chat/Performance/Chat.perf.tsx renamed to docs/src/examples/components/Chat/Performance/ChatDuplicateMessages.perf.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const janeAvatar = {
1212
status: { color: 'green', icon: 'stardust-checkmark' },
1313
}
1414

15-
const ChatExample = () => {
15+
const ChatDuplicateMessagesPerf = () => {
1616
return (
1717
<Provider
1818
theme={{
@@ -48,4 +48,7 @@ const ChatExample = () => {
4848
)
4949
}
5050

51-
export default ChatExample
51+
ChatDuplicateMessagesPerf.iterations = 5000
52+
ChatDuplicateMessagesPerf.filename = 'ChatDuplicateMessages.perf.tsx'
53+
54+
export default ChatDuplicateMessagesPerf
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Chat } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const ChatMinimalPerf = () => <Chat />
5+
6+
ChatMinimalPerf.iterations = 5000
7+
ChatMinimalPerf.filename = 'ChatMinimal.perf.tsx'
8+
9+
export default ChatMinimalPerf

docs/src/examples/components/Chat/Performance/ChatWithPopover.perf.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Accessibility, Avatar, Chat, Menu, Provider, menuAsToolbarBehavior } from '@fluentui/react'
22
import * as _ from 'lodash'
3-
import * as React from 'react'
43
import cx from 'classnames'
4+
import * as React from 'react'
55

66
const avatars = {
77
ade:
@@ -96,7 +96,7 @@ class Popover extends React.Component<PopoverProps, PopoverState> {
9696
}
9797
}
9898

99-
const ChatWithPopover = () => {
99+
const ChatWithPopoverPerf = () => {
100100
return (
101101
<Provider
102102
theme={{
@@ -166,4 +166,7 @@ const ChatWithPopover = () => {
166166
)
167167
}
168168

169-
export default ChatWithPopover
169+
ChatWithPopoverPerf.iterations = 5000
170+
ChatWithPopoverPerf.filename = 'ChatWithPopover.perf.tsx'
171+
172+
export default ChatWithPopoverPerf

docs/src/examples/components/Chat/Performance/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import NonPublicSection from 'docs/src/components/ComponentDoc/NonPublicSection'
66
const Performance = () => (
77
<NonPublicSection title="Performance">
88
<ComponentPerfExample
9-
title="Default"
10-
description="A default test."
11-
examplePath="components/Chat/Performance/Chat.perf"
9+
title="Duplicate Messages"
10+
description="Chat with many duplicate messages."
11+
examplePath="components/Chat/Performance/ChatDuplicateMessages.perf"
1212
/>
1313
<ComponentPerfExample
1414
title="Chat with popover"
15-
description="Chat with actions menu in a popover"
15+
description="Chat with actions menu in a popover."
1616
examplePath="components/Chat/Performance/ChatWithPopover.perf"
1717
/>
1818
</NonPublicSection>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Checkbox } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const CheckboxMinimalPerf = () => <Checkbox />
5+
6+
CheckboxMinimalPerf.iterations = 5000
7+
CheckboxMinimalPerf.filename = 'CheckboxMinimal.perf.tsx'
8+
9+
export default CheckboxMinimalPerf
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Dialog } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const DialogMinimalPerf = () => <Dialog />
5+
6+
DialogMinimalPerf.iterations = 5000
7+
DialogMinimalPerf.filename = 'DialogMinimal.perf.tsx'
8+
9+
export default DialogMinimalPerf

docs/src/examples/components/Divider/Performance/Divider.perf.tsx

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Divider } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const DividerMinimalPerf = () => <Divider />
5+
6+
DividerMinimalPerf.iterations = 5000
7+
DividerMinimalPerf.filename = 'DividerMinimal.perf.tsx'
8+
9+
export default DividerMinimalPerf

docs/src/examples/components/Divider/Performance/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const Performance = () => (
88
<ComponentPerfExample
99
title="Default"
1010
description="A default test."
11-
examplePath="components/Divider/Performance/Divider.perf"
11+
examplePath="components/Divider/Performance/DividerMinimal.perf"
1212
/>
1313
</NonPublicSection>
1414
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Dropdown } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const DropdownMinimalPerf = () => <Dropdown />
5+
6+
DropdownMinimalPerf.iterations = 5000
7+
DropdownMinimalPerf.filename = 'DropdownMinimal.perf.tsx'
8+
9+
export default DropdownMinimalPerf
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Embed } from '@fluentui/react'
2+
import * as React from 'react'
3+
4+
const EmbedMinimalPerf = () => <Embed />
5+
6+
EmbedMinimalPerf.iterations = 5000
7+
EmbedMinimalPerf.filename = 'EmbedMinimal.perf.tsx'
8+
9+
export default EmbedMinimalPerf

0 commit comments

Comments
 (0)