Skip to content

Benchmarks for @shopify/toml-patch #5678

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

Open
wants to merge 1 commit into
base: graphite-base/5678
Choose a base branch
from
Open
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
71 changes: 71 additions & 0 deletions packages/app/src/cli/services/app/toml-patch-wasm.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {replaceArrayStrategy} from './patch-app-configuration-file.js'
import {updateTomlValues} from './toml-patch-wasm.js'
import {decodeToml, encodeToml} from '@shopify/cli-kit/node/toml'
import {deepMergeObjects} from '@shopify/cli-kit/common/object'
import {describe, bench} from 'vitest'

// Sample TOML content for testing
const sampleToml = `
# This is a sample TOML file
title = "TOML Example"

[owner]
name = "Test User"
organization = "Test Org"

[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ] # Comment after array
enabled = true
`

function createPatchFromDottedPath(keyPath: string, value: unknown): {[key: string]: unknown} {
const keys = keyPath.split('.')
if (keys.length === 1) {
return {[keyPath]: value}
}

const obj: {[key: string]: unknown} = {}
let currentObj = obj

for (let i = 0; i < keys.length - 1; i++) {
const key = keys[i]
if (key) {
currentObj[key] = {}
currentObj = currentObj[key] as {[key: string]: unknown}
}
}

const lastKey = keys[keys.length - 1]
if (lastKey) {
currentObj[lastKey] = value
}

return obj
}

describe('WASM TOML Patch Integration', () => {
bench('time how long to update TOML, using WASM wrapper', async () => {
await updateTomlValues(sampleToml, [
[['owner', 'dotted', 'notation'], 123.5],
[['database', 'server'], 'changed'],
[['top_level'], true],
])
})

bench('time how long to update TOML, using plain JS', async () => {
const configValues = [
['owner.dotted.notation', 123.5],
['database.server', 'changed'],
['top_level', true],
] as const
const patch = configValues.reduce((acc, [keyPath, value]) => {
const valuePatch = createPatchFromDottedPath(keyPath, value)
return deepMergeObjects(acc, valuePatch, replaceArrayStrategy)
}, {})

const configuration = decodeToml(sampleToml)
const updatedConfig = deepMergeObjects(configuration, patch, replaceArrayStrategy)
encodeToml(updatedConfig)
})
})
8 changes: 7 additions & 1 deletion packages/eslint-plugin-cli/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ module.exports = {
},
overrides: [
{
files: ['**/*.test.ts', '**/*.test.tsx', '**/*.test-data.ts', '**/testing/*.{ts,tsx}'],
files: ['**/*.test.ts', '**/*.test.tsx', '**/*.test-data.ts', '**/testing/*.{ts,tsx}', '**/*.bench.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-restricted-syntax': 'off',
Expand All @@ -215,5 +215,11 @@ module.exports = {
'no-restricted-globals': 'off',
},
},
{
files: ['**/*.bench.ts'],
rules: {
'vitest/consistent-test-it': 'off',
},
},
],
}
Loading