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

perf: add base perf examples #2164

Merged
merged 6 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions build/gulp/tasks/perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ const createMarkdownTable = (

return markdownTable([
['Example', ...fieldLabels],
..._.map(exampleMeasures, (exampleMeasure, exampleName) => [
exampleName,
...fieldValues[exampleName],
]),
..._.sortBy(
_.map(exampleMeasures, (exampleMeasure, exampleName) => [
exampleName,
...fieldValues[exampleName],
]),
row => -row[fields.indexOf('median')],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've sorted the yarn perf results by their median values with the slowest components up top.

),
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,13 @@ class ComponentExample extends React.Component<ComponentExampleProps, ComponentE

render() {
const {
component,
children,
currentCode,
currentCodeLanguage,
currentCodePath,
error,
description,
defaultExport,
onError,
title,
wasCodeChanged,
Expand Down Expand Up @@ -519,7 +519,7 @@ class ComponentExample extends React.Component<ComponentExampleProps, ComponentE
resolver={importResolver}
/>
) : (
React.createElement(component)
React.createElement(defaultExport)
)}
</VariableResolver>
</Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import * as React from 'react'

import { ExampleSource } from 'docs/src/types'
import { componentAPIs as APIdefinitions, ComponentAPIs } from './componentAPIs'
import getExampleModule from './getExampeSource'
import getExampleModule from './getExampeModule'

export type ComponentSourceManagerRenderProps = ComponentSourceManagerState & {
component: React.ElementType
defaultExport: React.ElementType
namedExports: { [key: string]: React.ElementType }
handleCodeAPIChange: (newApi: keyof ComponentAPIs) => void
handleCodeChange: (newCode: string) => void
handleCodeFormat: () => void
Expand All @@ -23,7 +24,8 @@ export type ComponentSourceManagerProps = {
}

type ComponentSourceManagerAPIs = ComponentAPIs<{
component: React.ElementType
defaultExport: React.ElementType
namedExports: { [key: string]: React.ElementType }
sourceCode: ExampleSource | undefined
supported: boolean
}>
Expand Down Expand Up @@ -54,7 +56,8 @@ export default class ComponentSourceManager extends React.Component<

return {
...definition,
component: module && module.component,
defaultExport: module && module.defaultExport,
namedExports: module && module.namedExports,
sourceCode: module ? module.source : '',
supported: !!module,
}
Expand Down Expand Up @@ -139,7 +142,8 @@ export default class ComponentSourceManager extends React.Component<
render() {
return this.props.children({
...this.state,
component: this.state.componentAPIs[this.state.currentCodeAPI].component,
defaultExport: this.state.componentAPIs[this.state.currentCodeAPI].defaultExport,
namedExports: this.state.componentAPIs[this.state.currentCodeAPI].namedExports,
handleCodeAPIChange: this.handleCodeAPIChange,
handleCodeChange: this.handleCodeChange,
handleCodeFormat: this.handleCodeFormat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ import { componentAPIs, ComponentAPIs } from './componentAPIs'
const getExampleModule = (
examplePath: string,
componentAPI: keyof ComponentAPIs,
): { component: React.ElementType; source: ExampleSource } | undefined => {
):
| {
defaultExport: React.ElementType
namedExports: { [key: string]: React.ElementType }
source: ExampleSource
}
| undefined => {
const fileSuffix = componentAPIs[componentAPI].fileSuffix

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

try {
return {
component: examplesContext(modulePath).default,
defaultExport: examplesContext(modulePath).default,
namedExports: examplesContext(modulePath),
source: exampleSourcesContext(sourcePath),
}
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Accordion } from '@fluentui/react'
import * as React from 'react'

const AccordionMinimalPerf = () => <Accordion />

AccordionMinimalPerf.iterations = 5000
AccordionMinimalPerf.filename = 'AccordionMinimal.perf.tsx'

export default AccordionMinimalPerf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Alert } from '@fluentui/react'
import * as React from 'react'

const AlertMinimalPerf = () => <Alert />

AlertMinimalPerf.iterations = 5000
AlertMinimalPerf.filename = 'AlertMinimal.perf.tsx'

export default AlertMinimalPerf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Animation } from '@fluentui/react'
import * as React from 'react'

const AnimationMinimalPerf = () => <Animation />

AnimationMinimalPerf.iterations = 5000
AnimationMinimalPerf.filename = 'AnimationMinimal.perf.tsx'

export default AnimationMinimalPerf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Attachment } from '@fluentui/react'
import * as React from 'react'

const AttachmentMinimalPerf = () => <Attachment />

AttachmentMinimalPerf.iterations = 5000
AttachmentMinimalPerf.filename = 'AttachmentMinimal.perf.tsx'

export default AttachmentMinimalPerf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Attachment } from '@fluentui/react'
import * as React from 'react'

const AttachmentSlotsPerf = () => (
<Attachment
actionable
icon="table"
header="Document.docx"
description="800 Kb"
action={{ icon: 'more', title: 'More Action' }}
progress={33}
/>
)

AttachmentSlotsPerf.iterations = 5000
AttachmentSlotsPerf.filename = 'AttachmentSlots.perf.tsx'

export default AttachmentSlotsPerf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Avatar } from '@fluentui/react'
import * as React from 'react'

const AvatarMinimalPerf = () => <Avatar />

AvatarMinimalPerf.iterations = 5000
AvatarMinimalPerf.filename = 'AvatarMinimal.perf.tsx'

export default AvatarMinimalPerf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Box } from '@fluentui/react'
import * as React from 'react'

const BoxMinimalPerf = () => <Box />

BoxMinimalPerf.iterations = 5000
BoxMinimalPerf.filename = 'BoxMinimal.perf.tsx'

export default BoxMinimalPerf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Button } from '@fluentui/react'
import * as React from 'react'

const ButtonMinimalPerf = () => <Button />

ButtonMinimalPerf.iterations = 5000
ButtonMinimalPerf.filename = 'ButtonMinimal.perf.tsx'

export default ButtonMinimalPerf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Button } from '@fluentui/react'
import * as React from 'react'

const ButtonSlotsPerf = () => (
<Button
icon="play"
content="Click here"
loader={{
delay: 200,
inline: true,
label: 'Loading',
labelPosition: 'end',
size: 'smallest',
}}
/>
)

ButtonSlotsPerf.iterations = 5000
ButtonSlotsPerf.filename = 'ButtonSlots.perf.tsx'

export default ButtonSlotsPerf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Performance = () => (
<ComponentPerfExample
title="Default"
description="A default test."
examplePath="components/Button/Performance/Button.perf"
examplePath="components/Button/Performance/ButtonSlots.perf"
/>
</NonPublicSection>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Carousel } from '@fluentui/react'
import * as React from 'react'

const CarouselMinimalPerf = () => <Carousel />

CarouselMinimalPerf.iterations = 5000
CarouselMinimalPerf.filename = 'CarouselMinimal.perf.tsx'

export default CarouselMinimalPerf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const janeAvatar = {
status: { color: 'green', icon: 'stardust-checkmark' },
}

const ChatExample = () => {
const ChatDuplicateMessagesPerf = () => {
return (
<Provider
theme={{
Expand Down Expand Up @@ -48,4 +48,7 @@ const ChatExample = () => {
)
}

export default ChatExample
ChatDuplicateMessagesPerf.iterations = 5000
ChatDuplicateMessagesPerf.filename = 'ChatDuplicateMessages.perf.tsx'

export default ChatDuplicateMessagesPerf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Chat } from '@fluentui/react'
import * as React from 'react'

const ChatMinimalPerf = () => <Chat />

ChatMinimalPerf.iterations = 5000
ChatMinimalPerf.filename = 'ChatMinimal.perf.tsx'

export default ChatMinimalPerf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Accessibility, Avatar, Chat, Menu, Provider, menuAsToolbarBehavior } from '@fluentui/react'
import * as _ from 'lodash'
import * as React from 'react'
import cx from 'classnames'
import * as React from 'react'

const avatars = {
ade:
Expand Down Expand Up @@ -96,7 +96,7 @@ class Popover extends React.Component<PopoverProps, PopoverState> {
}
}

const ChatWithPopover = () => {
const ChatWithPopoverPerf = () => {
return (
<Provider
theme={{
Expand Down Expand Up @@ -166,4 +166,7 @@ const ChatWithPopover = () => {
)
}

export default ChatWithPopover
ChatWithPopoverPerf.iterations = 5000
ChatWithPopoverPerf.filename = 'ChatWithPopover.perf.tsx'

export default ChatWithPopoverPerf
8 changes: 4 additions & 4 deletions docs/src/examples/components/Chat/Performance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import NonPublicSection from 'docs/src/components/ComponentDoc/NonPublicSection'
const Performance = () => (
<NonPublicSection title="Performance">
<ComponentPerfExample
title="Default"
description="A default test."
examplePath="components/Chat/Performance/Chat.perf"
title="Duplicate Messages"
description="Chat with many duplicate messages."
examplePath="components/Chat/Performance/ChatDuplicateMessages.perf"
/>
<ComponentPerfExample
title="Chat with popover"
description="Chat with actions menu in a popover"
description="Chat with actions menu in a popover."
examplePath="components/Chat/Performance/ChatWithPopover.perf"
/>
</NonPublicSection>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Checkbox } from '@fluentui/react'
import * as React from 'react'

const CheckboxMinimalPerf = () => <Checkbox />

CheckboxMinimalPerf.iterations = 5000
CheckboxMinimalPerf.filename = 'CheckboxMinimal.perf.tsx'

export default CheckboxMinimalPerf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Dialog } from '@fluentui/react'
import * as React from 'react'

const DialogMinimalPerf = () => <Dialog />

DialogMinimalPerf.iterations = 5000
DialogMinimalPerf.filename = 'DialogMinimal.perf.tsx'

export default DialogMinimalPerf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Divider } from '@fluentui/react'
import * as React from 'react'

const DividerMinimalPerf = () => <Divider />

DividerMinimalPerf.iterations = 5000
DividerMinimalPerf.filename = 'DividerMinimal.perf.tsx'

export default DividerMinimalPerf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Performance = () => (
<ComponentPerfExample
title="Default"
description="A default test."
examplePath="components/Divider/Performance/Divider.perf"
examplePath="components/Divider/Performance/DividerMinimal.perf"
/>
</NonPublicSection>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Dropdown } from '@fluentui/react'
import * as React from 'react'

const DropdownMinimalPerf = () => <Dropdown />

DropdownMinimalPerf.iterations = 5000
DropdownMinimalPerf.filename = 'DropdownMinimal.perf.tsx'

export default DropdownMinimalPerf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Embed } from '@fluentui/react'
import * as React from 'react'

const EmbedMinimalPerf = () => <Embed />

EmbedMinimalPerf.iterations = 5000
EmbedMinimalPerf.filename = 'EmbedMinimal.perf.tsx'

export default EmbedMinimalPerf
Loading