Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Performance Profiling #12474

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 7 additions & 5 deletions packages/fluentui/perf/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@babel/polyfill';

import { Provider, Telemetry, themes } from '@fluentui/react-northstar';
import { Provider, Telemetry, themes, createRenderer } from '@fluentui/react-northstar';
import * as _ from 'lodash';
import * as minimatch from 'minimatch';
import * as React from 'react';
Expand All @@ -14,9 +14,7 @@ const Profiler = (React as any).unstable_Profiler;
const mountNode = document.querySelector('#root');
const performanceExamplesContext = require.context('docs/src/examples/', true, /.perf.tsx$/);

// Heads up!
// We want to randomize examples to avoid any notable issues with always first example
const performanceExampleNames: string[] = _.shuffle(performanceExamplesContext.keys());
const performanceExampleNames: string[] = performanceExamplesContext.keys();

const asyncRender = (element: React.ReactElement<any>, container: Element) =>
new Promise(resolve => {
Expand All @@ -34,8 +32,12 @@ const renderCycle = async (
let profilerMeasure: ProfilerMeasure;
const telemetryRef: React.Ref<Telemetry> = React.createRef();

if ((window as any).CLEAR_RESOLVE_STYLES_CACHE) {
console.log('---- render cycle ---- ');
(window as any).CLEAR_RESOLVE_STYLES_CACHE();
}
await asyncRender(
<Provider theme={themes.teams} telemetryRef={telemetryRef}>
<Provider theme={themes.teams} renderer={createRenderer()} telemetryRef={telemetryRef}>
<Profiler
id={exampleName}
onRender={(id: string, phase: string, actualTime: number, startTime: number, commitTime: number) => {
Expand Down
10 changes: 8 additions & 2 deletions packages/fluentui/react-bindings/src/styles/resolveStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ export type ResolveStylesResult = {
};

// this weak map is used as cache for the classes
const classesCache = new WeakMap<ThemePrepared, Record<string, string>>();
let classesCache = new WeakMap<ThemePrepared, Record<string, string>>();

// this weak map is used as cache for the styles
const stylesCache = new WeakMap<ThemePrepared, Record<string, ICSSInJSStyle>>();
let stylesCache = new WeakMap<ThemePrepared, Record<string, ICSSInJSStyle>>();

(window as any).CLEAR_RESOLVE_STYLES_CACHE = () => {
console.log('clear cache!');
classesCache = new WeakMap<ThemePrepared, Record<string, string>>();
stylesCache = new WeakMap<ThemePrepared, Record<string, ICSSInJSStyle>>();
};

/**
* Both resolvedStyles and classes are objects of getters with lazy evaluation
Expand Down