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

enhance(grapher): record PerformanceMeasurements #3913

Merged
merged 1 commit into from
Sep 4, 2024
Merged
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
51 changes: 50 additions & 1 deletion packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,16 @@ export class Grapher
get tableAfterAuthorTimelineAndActiveChartTransform(): OwidTable {
const table = this.tableAfterAuthorTimelineFilter
if (!this.isReady || !this.isOnChartOrMapTab) return table
return this.chartInstance.transformTable(table)

const startMark = performance.now()

const transformedTable = this.chartInstance.transformTable(table)

this.createPerformanceMeasurement(
"chartInstance.transformTable",
startMark
)
return transformedTable
}

@computed get chartInstance(): ChartInterface {
Expand Down Expand Up @@ -888,6 +897,34 @@ export class Grapher
)
}

// Exclusively used for the performance.measurement API, so that DevTools can show some context
private createPerformanceMeasurement(
name: string,
startMark: number
): void {
const endMark = performance.now()
const detail = {
devtools: {
track: "Grapher",
properties: [
["slug", this.slug],
["chartType", this.type],
["tab", this.tab],
],
},
}

try {
performance.measure(name, {
start: startMark,
end: endMark,
detail,
})
} catch {
// In old browsers, the above may throw an error - just ignore it
}
}

@action.bound
async downloadLegacyDataFromOwidVariableIds(
inputTableTransformer?: ChartTableTransformer
Expand All @@ -898,6 +935,8 @@ export class Grapher

try {
let variablesDataMap: MultipleOwidVariableDataDimensionsMap

const startMark = performance.now()
if (this.useAdminAPI) {
// TODO grapher model: switch this to downloading multiple data and metadata files
variablesDataMap = await loadVariablesDataAdmin(
Expand All @@ -910,6 +949,10 @@ export class Grapher
this.dataApiUrl
)
}
this.createPerformanceMeasurement(
"downloadVariablesData",
startMark
)

this._receiveOwidDataAndApplySelection(
variablesDataMap,
Expand Down Expand Up @@ -940,10 +983,16 @@ export class Grapher
inputTableTransformer?: ChartTableTransformer
): void {
// TODO grapher model: switch this to downloading multiple data and metadata files

const startMark = performance.now()
const { dimensions, table } = legacyToOwidTableAndDimensions(
json,
legacyConfig
)
this.createPerformanceMeasurement(
"legacyToOwidTableAndDimensions",
startMark
)

if (inputTableTransformer)
this.inputTable = inputTableTransformer(table)
Expand Down