Skip to content

Commit

Permalink
Merge d6676dd into 5f9127a
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski authored Jun 16, 2024
2 parents 5f9127a + d6676dd commit 77b6f34
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .changeset/ten-toes-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'reassure': minor
'@callstack/reassure-compare': minor
---

Expose "Warmup Runs" and "Render Issues" in markdown report
1 change: 1 addition & 0 deletions packages/compare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export type {
CompareEntry,
AddedEntry,
RemovedEntry,
RenderIssues,
} from './types';
38 changes: 31 additions & 7 deletions packages/compare/src/output/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import {
formatDurationChange,
} from '../utils/format';
import * as md from '../utils/markdown';
import type { AddedEntry, CompareEntry, CompareResult, RemovedEntry, MeasureEntry, MeasureMetadata } from '../types';
import type {
AddedEntry,
CompareEntry,
CompareResult,
RemovedEntry,
MeasureEntry,
MeasureMetadata,
RenderIssues,
} from '../types';
import { collapsibleSection } from '../utils/markdown';

const tableHeader = ['Name', 'Type', 'Duration', 'Count'] as const;
Expand Down Expand Up @@ -76,7 +84,7 @@ function buildMarkdown(data: CompareResult) {
result += `\n${buildSummaryTable(data.countChanged)}`;
result += `\n${buildDetailsTable(data.countChanged)}`;
result += `\n\n${md.heading3('Render Issues')}`;
result += `\n${buildRedundantRendersTable(data.renderIssues)}`;
result += `\n${buildRenderIssuesTable(data.renderIssues)}`;
}

result += `\n\n${md.heading3('Added Scenarios')}`;
Expand Down Expand Up @@ -158,6 +166,7 @@ function buildDurationDetails(title: string, entry: MeasureEntry) {
`Mean: ${formatDuration(entry.meanDuration)}`,
`Stdev: ${formatDuration(entry.stdevDuration)} (${formatPercent(relativeStdev)})`,
entry.durations ? `Runs: ${formatRunDurations(entry.durations)}` : '',
entry.warmupDurations ? `Warmup runs: ${formatRunDurations(entry.warmupDurations)}` : '',
]
.filter(Boolean)
.join(`<br/>`);
Expand All @@ -171,6 +180,7 @@ function buildCountDetails(title: string, entry: MeasureEntry) {
`Mean: ${formatCount(entry.meanCount)}`,
`Stdev: ${formatCount(entry.stdevCount)} (${formatPercent(relativeStdev)})`,
entry.counts ? `Runs: ${entry.counts.map(formatCount).join(' ')}` : '',
buildRenderIssuesList(entry.issues),
]
.filter(Boolean)
.join(`<br/>`);
Expand All @@ -180,7 +190,7 @@ function formatRunDurations(values: number[]) {
return values.map((v) => (Number.isInteger(v) ? `${v}` : `${v.toFixed(1)}`)).join(' ');
}

function buildRedundantRendersTable(entries: Array<CompareEntry | AddedEntry>) {
function buildRenderIssuesTable(entries: Array<CompareEntry | AddedEntry>) {
if (!entries.length) return md.italic('There are no entries');

const tableHeader = ['Name', 'Initial Updates', 'Redundant Updates'] as const;
Expand All @@ -193,16 +203,30 @@ function buildRedundantRendersTable(entries: Array<CompareEntry | AddedEntry>) {
return markdownTable([tableHeader, ...rows]);
}

function formatInitialUpdates(count: number | undefined) {
function buildRenderIssuesList(issues: RenderIssues | undefined) {
if (issues == null) return '';

const output = ['Render issues:'];
if (issues?.initialUpdateCount) {
output.push(` - Initial updates: ${formatInitialUpdates(issues.initialUpdateCount, false)}`);
}
if (issues?.redundantUpdates?.length) {
output.push(` - Redundant updates: ${formatRedundantUpdates(issues.redundantUpdates, false)}`);
}

return output.join('<br/>');
}

function formatInitialUpdates(count: number | undefined, showSymbol: boolean = true) {
if (count == null) return '?';
if (count === 0) return '-';

return `${count} 🔴`;
return `${count}${showSymbol ? ' 🔴' : ''}`;
}

function formatRedundantUpdates(redundantUpdates: number[] | undefined) {
function formatRedundantUpdates(redundantUpdates: number[] | undefined, showSymbol: boolean = true) {
if (redundantUpdates == null) return '?';
if (redundantUpdates.length === 0) return '-';

return `${redundantUpdates.length} (${redundantUpdates.join(', ')}) 🔴`;
return `${redundantUpdates.length} (${redundantUpdates.join(', ')})${showSymbol ? ' 🔴' : ''}`;
}
12 changes: 6 additions & 6 deletions packages/compare/src/type-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export const MeasureHeaderScheme = z.object({
metadata: MeasureMetadataScheme,
});

export const RenderIssuesScheme = z.object({
initialUpdateCount: z.number().optional(),
redundantUpdates: z.array(z.number()).optional(),
});

/** Entry in the performance results file. */
export const MeasureEntryScheme = z.object({
/** Name of the test scenario. */
Expand Down Expand Up @@ -44,10 +49,5 @@ export const MeasureEntryScheme = z.object({
/** Array of measured render/execution counts for each run. */
counts: z.array(z.number()),

issues: z.optional(
z.object({
initialUpdateCount: z.number().optional(),
redundantUpdates: z.array(z.number()).optional(),
})
),
issues: z.optional(RenderIssuesScheme),
});
8 changes: 7 additions & 1 deletion packages/compare/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/** Parsed performance results file. */
import type { z } from 'zod';
import type { MeasureEntryScheme, MeasureHeaderScheme, MeasureMetadataScheme } from './type-schemas';
import type {
MeasureEntryScheme,
MeasureHeaderScheme,
MeasureMetadataScheme,
RenderIssuesScheme,
} from './type-schemas';

export type MeasureHeader = z.infer<typeof MeasureHeaderScheme>;
export type MeasureMetadata = z.infer<typeof MeasureMetadataScheme>;
export type MeasureEntry = z.infer<typeof MeasureEntryScheme>;
export type RenderIssues = z.infer<typeof RenderIssuesScheme>;
export type MeasureType = MeasureEntry['type'];

export interface MeasureResults {
Expand Down
1 change: 1 addition & 0 deletions packages/reassure/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ export type {
CompareEntry,
AddedEntry,
RemovedEntry,
RenderIssues,
} from '@callstack/reassure-compare';

0 comments on commit 77b6f34

Please sign in to comment.