Skip to content

Commit

Permalink
Start adding combination.dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 12, 2021
1 parent 5227160 commit 475a5f9
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 112 deletions.
56 changes: 35 additions & 21 deletions benchmark/history.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
},
"combinations": [
{
"taskId": "random",
"runnerId": "node",
"systemId": "default_system",
"dimensions": {
"task": "random",
"runner": "node",
"system": "default_system"
},
"stats": {
"median": 6.55279933481153,
"mean": 6.699839477087952,
Expand All @@ -45,9 +47,11 @@
}
},
{
"taskId": "empty",
"runnerId": "node",
"systemId": "default_system",
"dimensions": {
"task": "empty",
"runner": "node",
"system": "default_system"
},
"stats": {
"samples": 66,
"loops": 2368,
Expand Down Expand Up @@ -96,9 +100,11 @@
},
"combinations": [
{
"taskId": "real",
"runnerId": "node",
"systemId": "default_system",
"dimensions": {
"task": "real",
"runner": "node",
"system": "default_system"
},
"stats": {
"samples": 123,
"loops": 123,
Expand Down Expand Up @@ -147,9 +153,11 @@
},
"combinations": [
{
"taskId": "random",
"runnerId": "node",
"systemId": "default_system",
"dimensions": {
"task": "random",
"runner": "node",
"system": "default_system"
},
"stats": {
"samples": 7,
"loops": 1707,
Expand All @@ -170,9 +178,11 @@
}
},
{
"taskId": "fixed",
"runnerId": "node",
"systemId": "default_system",
"dimensions": {
"task": "fixed",
"runner": "node",
"system": "default_system"
},
"stats": {
"samples": 6,
"loops": 11,
Expand Down Expand Up @@ -221,9 +231,11 @@
},
"combinations": [
{
"taskId": "random",
"runnerId": "node",
"systemId": "default_system",
"dimensions": {
"task": "random",
"runner": "node",
"system": "default_system"
},
"stats": {
"samples": 195,
"loops": 64351,
Expand All @@ -244,9 +256,11 @@
}
},
{
"taskId": "real",
"runnerId": "node",
"systemId": "default_system",
"dimensions": {
"task": "real",
"runner": "node",
"system": "default_system"
},
"stats": {
"samples": 123,
"loops": 123,
Expand Down
4 changes: 4 additions & 0 deletions src/combination/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// previews and `dev`
export const DIMENSIONS = [
{
// Name used as property internally and when saving
propName: 'task',
// Name used in output and error messages
messageName: 'task',
// Property name for the identifier
Expand All @@ -20,12 +22,14 @@ export const DIMENSIONS = [
createdByUser: true,
},
{
propName: 'runner',
messageName: 'runner',
idName: 'runnerId',
titleName: 'runnerTitle',
createdByUser: false,
},
{
propName: 'system',
messageName: 'system',
idName: 'systemId',
titleName: 'systemTitle',
Expand Down
16 changes: 15 additions & 1 deletion src/combination/ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ const isNotDuplicate = function ({ dimension, id }, index, combinationIds) {
export const getCombinationIds = function (combination) {
return DIMENSIONS.map((dimension) => ({
dimension,
id: combination[dimension.idName],
id: combination.dimensions[dimension.propName][dimension.idName],
}))
}

export const getDimensionId = function (propName, { dimensions }) {
const { idName } = DIMENSIONS.find(
(dimension) => dimension.propName === propName,
)
return dimensions[propName][idName]
}

export const getDimensionTitle = function (propName, { dimensions }) {
const { titleName } = DIMENSIONS.find(
(dimension) => dimension.propName === propName,
)
return dimensions[propName][titleName]
}
27 changes: 5 additions & 22 deletions src/combination/list/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,9 @@ const getCombinationsProduct = function ({ tasks, inputs, systemId }) {
throw new UserError(`Please specify some "tasks".`)
}

return tasks.map(
({
taskPath,
taskId,
runnerId,
runnerSpawn,
runnerSpawnOptions,
runnerVersions,
runnerConfig,
}) => ({
taskPath,
taskId,
runnerId,
runnerSpawn,
runnerSpawnOptions,
runnerVersions,
runnerConfig,
inputs,
systemId,
stats: {},
}),
)
return tasks.map(({ taskId, taskPath, runner }) => ({
dimensions: { task: { taskId, taskPath }, runner, system: { systemId } },
inputs,
stats: {},
}))
}
25 changes: 14 additions & 11 deletions src/combination/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sortOn from 'sort-on'
import { getMean } from '../stats/sum.js'
import { groupBy } from '../utils/group.js'

import { getCombinationsIds } from './ids.js'
import { getCombinationsIds, getDimensionId } from './ids.js'

// Sort `result.combinations` based on their `stats.mean`.
// Combinations with the same dimension are grouped together in the sorting
Expand All @@ -19,22 +19,25 @@ import { getCombinationsIds } from './ids.js'
export const sortCombinations = function (result) {
const { combinations } = result
const combinationsIds = getCombinationsIds(combinations)
const idNames = [...new Set(combinationsIds.map(getIdName))]
const sortFunctions = idNames.map((idName) =>
getSortFunction(idName, combinations),
const dimensions = [...new Set(combinationsIds.map(getDimension))]
const sortFunctions = dimensions.map((dimension) =>
getSortFunction(dimension, combinations),
)
const combinationsA = sortOn(combinations, sortFunctions)
return { ...result, combinations: combinationsA }
}

const getIdName = function ({ dimension: { idName } }) {
return idName
const getDimension = function ({ dimension: { propName } }) {
return propName
}

// Retrieve a function used to compare combinations for a specific dimension
const getSortFunction = function (idName, combinations) {
const meansOfMeans = mapObj(groupBy(combinations, idName), getMeanOfMeans)
return getCombinationOrder.bind(undefined, idName, meansOfMeans)
const getSortFunction = function (dimension, combinations) {
const meansOfMeans = mapObj(
groupBy(combinations, getDimensionId.bind(undefined, dimension)),
getMeanOfMeans,
)
return getCombinationOrder.bind(undefined, dimension, meansOfMeans)
}

// Retrieve the mean of all `stat.mean` for a specific dimension and id.
Expand All @@ -54,7 +57,7 @@ const isDefined = function (mean) {
return mean !== undefined
}

const getCombinationOrder = function (idName, meansOfMeans, combination) {
const id = combination[idName]
const getCombinationOrder = function (dimension, meansOfMeans, combination) {
const id = getDimensionId(dimension, combination)
return meansOfMeans[id]
}
22 changes: 16 additions & 6 deletions src/combination/tasks/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,28 @@ export const findTasks = async function (

try {
const [{ taskIds }] = await measureCombinations(
[{ taskPath, runnerSpawn, runnerSpawnOptions, runnerConfig, inputs: [] }],
[
{
dimensions: {
task: { taskPath },
runner: { runnerSpawn, runnerSpawnOptions, runnerConfig },
},
inputs: [],
},
],
{ precisionTarget: 0, cwd, previewState: { quiet: true }, stage: 'init' },
)
validateDuplicateTaskIds(taskIds)
return taskIds.map((taskId) => ({
taskId,
taskPath,
runnerId,
runnerSpawn,
runnerSpawnOptions,
runnerVersions,
runnerConfig,
runner: {
runnerId,
runnerSpawn,
runnerSpawnOptions,
runnerVersions,
runnerConfig,
},
}))
} catch (error) {
error.message = `In tasks file "${taskPath}" (runner "${runnerId}")\n${error.message}`
Expand Down
46 changes: 34 additions & 12 deletions src/history/normalize/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@
// We try to persist everything, so that `show` report the same information.
// We try to only persist what cannot be computed runtime.
export const compressResult = function ({ combinations, ...result }) {
const combinationsA = combinations.map(compressCombination)
const combinationsA = combinations.map((combination) =>
compressCombination({ combination }),
)
return { ...result, combinations: combinationsA }
}

const compressCombination = function ({
stats,
stats: { histogram, quantiles, mean },
...combination
combination,
combination: {
dimensions: {
task: { taskId },
runner: { runnerId },
system: { systemId },
},
stats,
stats: { histogram, quantiles, mean },
},
}) {
const histogramA = compressHistogram(histogram, mean)
const quantilesA = compressQuantiles(quantiles, mean)
const statsA = { ...stats, histogram: histogramA, quantiles: quantilesA }
return { ...combination, stats: statsA }
return {
...combination,
dimensions: { task: taskId, runner: runnerId, system: systemId },
stats: { ...stats, histogram: histogramA, quantiles: quantilesA },
}
}

const compressHistogram = function (histogram, mean) {
Expand All @@ -30,20 +42,30 @@ const compressBucket = function ({ start, end, frequency }, mean) {
}

// Restore original results after loading
export const decompressResult = function ({ combinations, ...result }) {
const combinationsA = combinations.map(decompressCombination)
return { ...result, combinations: combinationsA }
export const decompressResult = function (result) {
const combinations = result.combinations.map((combination) =>
decompressCombination({ combination }),
)
return { ...result, combinations }
}

const decompressCombination = function ({
stats,
stats: { histogram, quantiles, mean },
...combination
combination,
combination: {
dimensions: { task, runner, system },
stats,
stats: { histogram, quantiles, mean },
},
}) {
const histogramA = decompressHistogram(histogram, mean)
const quantilesA = decompressQuantiles(quantiles, mean)
return {
...combination,
dimensions: {
task: { taskId: task },
runner: { runnerId: runner },
system: { systemId: system },
},
stats: { ...stats, histogram: histogramA, quantiles: quantilesA },
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/history/normalize/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { migrateResults } from './migrate.js'
// Normalize results on load
export const loadResults = function (results, select) {
const resultsA = migrateResults(results)
const resultsB = selectResults(resultsA, select)
const resultsC = resultsB.map(decompressResult)
const resultsB = resultsA.map(decompressResult)
const resultsC = selectResults(resultsB, select)
const resultsD = sortResults(resultsC)
return resultsD
}
Expand Down
21 changes: 19 additions & 2 deletions src/report/normalize/titles_add.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,29 @@ export const addCombinationsTitles = function (result, titles, showTitles) {
const addCombinationTitles = function (combination, titles) {
const combinationIds = getCombinationIds(combination)
return combinationIds.reduce(
(combinationA, { dimension: { idName, titleName } }) =>
addTitle(combinationA, { idName, titleName, titles }),
(combinationA, { dimension }) =>
addCombinationTitle({ combination: combinationA, dimension, titles }),
combination,
)
}

const addCombinationTitle = function ({
combination,
combination: { dimensions },
dimension: { propName, idName, titleName },
titles,
}) {
const dimension = addTitle(dimensions[propName], {
idName,
titleName,
titles,
})
return {
...combination,
dimensions: { ...dimensions, [propName]: dimension },
}
}

// Add `footer.systems[*].title`
export const addFooterTitles = function (footer, titles, showTitles) {
const titlesA = showTitles ? titles : {}
Expand Down
Loading

0 comments on commit 475a5f9

Please sign in to comment.