From 9a8191d36789cfa65f9662f124e10404803e15ea Mon Sep 17 00:00:00 2001 From: Maurice Date: Sat, 10 Oct 2026 11:49:00 +0200 Subject: [PATCH] chore: remove root scripts nothing runs any more The two React profiler readers were one-off analysis helpers, and the i18n migration read client/src/i18n/translations, which has been gone since the locales moved to shared/. --- scripts/analyze-devtool-profiler.cjs | 133 --------------------------- scripts/analyze-react-profiler.cjs | 96 ------------------- scripts/migrate-i18n.mts | 117 ----------------------- 3 files changed, 346 deletions(-) delete mode 100644 scripts/analyze-devtool-profiler.cjs delete mode 100644 scripts/analyze-react-profiler.cjs delete mode 100644 scripts/migrate-i18n.mts diff --git a/scripts/analyze-devtool-profiler.cjs b/scripts/analyze-devtool-profiler.cjs deleted file mode 100644 index 62737669d..000000000 --- a/scripts/analyze-devtool-profiler.cjs +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/env node -// Chrome Performance Trace Analyzer — outputs a compact summary -// Usage: node analyze-trace.js - -const fs = require('fs') -const path = require('path') - -const file = process.argv[2] -if (!file) { console.error('Usage: node analyze-trace.js '); process.exit(1) } - -console.log(`Reading ${path.basename(file)} (${(fs.statSync(file).size / 1e6).toFixed(1)} MB)...`) -const raw = fs.readFileSync(file, 'utf8') -console.log('Parsing...') -const trace = JSON.parse(raw) -const events = Array.isArray(trace) ? trace : (trace.traceEvents || []) -console.log(`Total events: ${events.length.toLocaleString()}\n`) - -// ── 1. Long Tasks (> 50ms on main thread) ──────────────────────────────────── -const LONG_TASK_MS = 50 -const tasks = events - .filter(e => e.ph === 'X' && e.dur && e.dur > LONG_TASK_MS * 1000) - .sort((a, b) => b.dur - a.dur) - .slice(0, 30) - -console.log(`═══ TOP LONG TASKS (>${LONG_TASK_MS}ms) ═══`) -for (const t of tasks) { - const ms = (t.dur / 1000).toFixed(1) - const name = t.name || '(unknown)' - const cat = t.cat || '' - console.log(` ${ms.padStart(8)}ms ${name} [${cat}]`) -} - -// ── 2. Summarise all complete events by name ────────────────────────────────── -const byName = new Map() -for (const e of events) { - if (e.ph !== 'X' || !e.dur) continue - const key = e.name - const existing = byName.get(key) - if (existing) { - existing.totalMs += e.dur / 1000 - existing.count++ - if (e.dur > existing.maxMs * 1000) existing.maxMs = e.dur / 1000 - } else { - byName.set(key, { totalMs: e.dur / 1000, count: 1, maxMs: e.dur / 1000 }) - } -} -const topByTotal = [...byName.entries()] - .sort((a, b) => b[1].totalMs - a[1].totalMs) - .slice(0, 40) - -console.log('\n═══ TOP EVENTS BY TOTAL TIME ═══') -console.log(' Total(ms) Max(ms) Count Name') -for (const [name, s] of topByTotal) { - console.log( - ` ${s.totalMs.toFixed(1).padStart(9)} ${s.maxMs.toFixed(1).padStart(7)} ${String(s.count).padStart(5)} ${name}` - ) -} - -// ── 3. React-specific events ────────────────────────────────────────────────── -const reactKeywords = ['react', 'React', 'setState', 'useState', 'useMemo', 'useEffect', - 'reconcil', 'Reconcil', 'render', 'Render', 'commit', 'Commit', 'fiber', 'Fiber', - 'Marker', 'MapView', 'photoUrl', 'createPlace', 'markers'] -const reactEvents = [...byName.entries()] - .filter(([name]) => reactKeywords.some(k => name.includes(k))) - .sort((a, b) => b[1].totalMs - a[1].totalMs) - .slice(0, 30) - -if (reactEvents.length > 0) { - console.log('\n═══ REACT / MAP EVENTS ═══') - for (const [name, s] of reactEvents) { - console.log(` ${s.totalMs.toFixed(1).padStart(9)}ms total ${s.maxMs.toFixed(1).padStart(7)}ms max ${s.count}x ${name}`) - } -} - -// ── 4. V8 / JS heavy hitters ───────────────────────────────────────────────── -const jsEvents = [...byName.entries()] - .filter(([, s]) => s.totalMs > 20) - .filter(([name]) => { - const cat = (events.find(e => e.name === name)?.cat || '') - return cat.includes('v8') || cat.includes('devtools.timeline') || name.includes('JS') || name.includes('Compile') || name.includes('GC') - }) - .sort((a, b) => b[1].totalMs - a[1].totalMs) - .slice(0, 20) - -if (jsEvents.length > 0) { - console.log('\n═══ V8 / JS EVENTS (>20ms total) ═══') - for (const [name, s] of jsEvents) { - console.log(` ${s.totalMs.toFixed(1).padStart(9)}ms ${s.count}x ${name}`) - } -} - -// ── 5. CPU profile — top self-time functions ───────────────────────────────── -const profileChunks = events.filter(e => e.name === 'ProfileChunk') -if (profileChunks.length > 0) { - const selfTime = new Map() - for (const chunk of profileChunks) { - const nodes = chunk.args?.data?.cpuProfile?.nodes || [] - const samples = chunk.args?.data?.cpuProfile?.samples || [] - const timeDeltas = chunk.args?.data?.timeDeltas || [] - // Build node map - const nodeMap = new Map(nodes.map(n => [n.id, n])) - // Accumulate self time per node - for (let i = 0; i < samples.length; i++) { - const nodeId = samples[i] - const dt = (timeDeltas[i] || 0) / 1000 // µs → ms - const node = nodeMap.get(nodeId) - if (!node) continue - const fn = node.callFrame?.functionName || '(anonymous)' - const url = node.callFrame?.url || '' - const line = node.callFrame?.lineNumber || 0 - const key = `${fn} @ ${url.split('/').slice(-2).join('/')}:${line}` - selfTime.set(key, (selfTime.get(key) || 0) + dt) - } - } - const topSelf = [...selfTime.entries()] - .sort((a, b) => b[1] - a[1]) - .slice(0, 40) - - console.log('\n═══ CPU PROFILE — TOP SELF-TIME FUNCTIONS ═══') - for (const [name, ms] of topSelf) { - console.log(` ${ms.toFixed(1).padStart(8)}ms ${name}`) - } -} - -// ── 6. Paint / Layout costs ─────────────────────────────────────────────────── -const renderCats = ['Layout', 'UpdateLayoutTree', 'Paint', 'CompositeLayers', 'RasterTask'] -console.log('\n═══ RENDERING COSTS ═══') -for (const cat of renderCats) { - const s = byName.get(cat) - if (s) console.log(` ${s.totalMs.toFixed(1).padStart(9)}ms total ${s.maxMs.toFixed(1).padStart(7)}ms max ${s.count}x ${cat}`) -} - -console.log('\nDone.') diff --git a/scripts/analyze-react-profiler.cjs b/scripts/analyze-react-profiler.cjs deleted file mode 100644 index 98f021fa3..000000000 --- a/scripts/analyze-react-profiler.cjs +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env node -const fs = require('fs') -const path = require('path') - -const file = process.argv[2] -if (!file) { console.error('Usage: node analyze-react-profiler.cjs '); process.exit(1) } - -const raw = JSON.parse(fs.readFileSync(path.resolve(file), 'utf8')) -const root = raw.dataForRoots[0] -const commits = root.commitData - -// snapshots: array of [fiberId, {displayName, ...}] -const nameMap = new Map() -for (const snap of root.snapshots) { - const id = snap[0] - const data = snap[1] - if (data?.displayName) nameMap.set(id, data.displayName) -} - -console.log(`Commits: ${commits.length} Tracked components: ${nameMap.size}`) - -// Probe the unit of fiberActualDurations against the known commit duration -// fiberActualDurations contains durations for the subtree — the root fiber's -// actual duration should be >= commit.duration. Find a plausible scale factor. -const c0 = commits[0] -const knownDur = c0.duration // already in ms per React DevTools spec -const rootId = root.rootID ?? 1 -// Check a few values to pick scale -const sampleDurs = c0.fiberActualDurations.slice(0, 10).map(e => e[1]) -console.log(`\nDebug — commit[0].duration=${knownDur}ms, first 5 raw fiberActualDurations values:`, sampleDurs.slice(0,5)) -// If max sample > 10*knownDur, values are in units of 1/100 ms; otherwise already ms -const maxSample = Math.max(...c0.fiberActualDurations.map(e => e[1])) -const scale = maxSample > knownDur * 10 ? 0.01 : 1 - -console.log(`Unit scale: ${scale === 0.01 ? '1/100 ms (dividing by 100)' : 'ms (no conversion)'}\n`) - -// --- 1. Commit summary --- -const fmt = (v) => v == null ? ' -' : (v * 1).toFixed(1).padStart(7) -console.log('=== Commit summary ===') -console.log(' # t(s) dur(ms) passive(ms) effects(ms) priority') -const sorted = [...commits].map((c, i) => ({ i, ...c })).sort((a, b) => b.duration - a.duration) -for (const c of sorted.slice(0, 15)) { - const ts = (c.timestamp / 1000).toFixed(3) - console.log(` ${String(c.i).padStart(2)} ${ts} ${fmt(c.duration)} ${fmt(c.passiveEffectDuration)} ${fmt(c.effectDuration)} ${c.priorityLevel ?? ''}`) -} - -// --- 2. Aggregate self + actual duration per component --- -const selfTotals = new Map() // name → { total, count, max } -const actualTotals = new Map() - -for (const commit of commits) { - for (const [id, raw] of commit.fiberActualDurations) { - const dur = raw * scale - const name = nameMap.get(id) ?? `(fiber#${id})` - const e = actualTotals.get(name) ?? { total: 0, count: 0, max: 0 } - e.total += dur; e.count += 1; e.max = Math.max(e.max, dur) - actualTotals.set(name, e) - } - for (const [id, raw] of commit.fiberSelfDurations) { - const dur = raw * scale - const name = nameMap.get(id) ?? `(fiber#${id})` - const e = selfTotals.get(name) ?? { total: 0, count: 0, max: 0 } - e.total += dur; e.count += 1; e.max = Math.max(e.max, dur) - selfTotals.set(name, e) - } -} - -const ranked = [...selfTotals.entries()] - .sort((a, b) => b[1].total - a[1].total) - .filter(([, s]) => s.total > 0.5) - -console.log('\n=== Top 40 components by SELF render time (excludes children) ===') -console.log(' Component Self total Renders Self max Actual total') -for (const [name, s] of ranked.slice(0, 40)) { - const actual = actualTotals.get(name) ?? { total: 0 } - console.log( - ` ${name.padEnd(48)} ${s.total.toFixed(1).padStart(8)} ms` + - ` ${String(s.count).padStart(6)}x` + - ` ${s.max.toFixed(1).padStart(7)} ms` + - ` ${actual.total.toFixed(1).padStart(10)} ms` - ) -} - -console.log('\n=== Most frequently re-rendering components (top 20) ===') -const byCount = [...selfTotals.entries()].sort((a, b) => b[1].count - a[1].count) -console.log(' Component Renders Self total') -for (const [name, s] of byCount.slice(0, 20)) { - console.log(` ${name.padEnd(48)} ${String(s.count).padStart(6)}x ${s.total.toFixed(1).padStart(8)} ms`) -} - -const totalPassive = commits.reduce((a, c) => a + (c.passiveEffectDuration ?? 0), 0) -const totalCommit = commits.reduce((a, c) => a + c.duration, 0) -console.log(`\n=== Totals ===`) -console.log(` Total commit render time: ${totalCommit.toFixed(1)} ms (${commits.length} commits)`) -console.log(` Total passive effect time: ${totalPassive.toFixed(1)} ms (useEffect)`) -console.log(` Avg commit duration: ${(totalCommit / commits.length).toFixed(1)} ms`) diff --git a/scripts/migrate-i18n.mts b/scripts/migrate-i18n.mts deleted file mode 100644 index fc26ae95b..000000000 --- a/scripts/migrate-i18n.mts +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env node -/** - * Extracts client locale files into per-namespace files under shared/src/i18n/{locale}/. - * Run with: npx tsx scripts/migrate-i18n.mts - * - * Safe to re-run — locale dirs are cleaned first. Hand-authored files - * (types.ts, languages.ts, index.ts) in shared/src/i18n/ are never touched. - */ -import { mkdir, rm, writeFile } from 'fs/promises' -import { dirname, join } from 'path' -import { fileURLToPath, pathToFileURL } from 'url' - -const __dirname = dirname(fileURLToPath(import.meta.url)) -const ROOT = join(__dirname, '..') -const TRANSLATIONS_DIR = join(ROOT, 'client/src/i18n/translations') -const I18N_OUT = join(ROOT, 'shared/src/i18n') - -// Maps locale code → source filename (without .ts) in client/src/i18n/translations/ -const LOCALE_FILE_MAP: Record = { - de: 'de', en: 'en', es: 'es', fr: 'fr', hu: 'hu', - it: 'it', tr: 'tr', ru: 'ru', zh: 'zh', 'zh-TW': 'zhTw', - nl: 'nl', id: 'id', ar: 'ar', br: 'br', cs: 'cs', - pl: 'pl', ja: 'ja', ko: 'ko', uk: 'uk', -} - -type TranslationValue = string | { name: string; category: string }[] -type LocaleStrings = Record - -async function loadLocale(code: string): Promise { - const filename = LOCALE_FILE_MAP[code] - if (!filename) throw new Error(`Unknown locale code: ${code}`) - const file = join(TRANSLATIONS_DIR, `${filename}.ts`) - const mod = await import(pathToFileURL(file).href) - return mod.default as LocaleStrings -} - -function serializeValue(value: TranslationValue, innerIndent: string): string { - if (Array.isArray(value)) { - // Pretty-print the array then re-indent each line after the first - const lines = JSON.stringify(value, null, 2).split('\n') - return lines.map((l, i) => (i === 0 ? l : innerIndent + l)).join('\n') - } - return JSON.stringify(value) -} - -async function writeLocaleDir(code: string, strings: LocaleStrings): Promise { - const outDir = join(I18N_OUT, code) - await mkdir(outDir, { recursive: true }) - - // Group keys by top-level namespace prefix (everything before the first dot) - const namespaces = new Map>() - for (const [key, value] of Object.entries(strings)) { - const ns = key.split('.')[0] ?? key - if (!namespaces.has(ns)) namespaces.set(ns, []) - namespaces.get(ns)!.push([key, value]) - } - - // Write one file per namespace - for (const [ns, entries] of namespaces) { - const lines: string[] = [ - `import type { TranslationStrings } from '../types'`, - ``, - `const ${ns}: TranslationStrings = {`, - ...entries.map(([k, v]) => ` ${JSON.stringify(k)}: ${serializeValue(v, ' ')},`), - `}`, - `export default ${ns}`, - ] - await writeFile(join(outDir, `${ns}.ts`), lines.join('\n') + '\n') - } - - // Write index.ts that merges all namespace files into a single locale object - const nsNames = [...namespaces.keys()] - const indexLines: string[] = [ - ...nsNames.map(ns => `import ${ns} from './${ns}'`), - ``, - `const locale = {`, - ...nsNames.map(ns => ` ...${ns},`), - `}`, - `export default locale`, - ] - await writeFile(join(outDir, 'index.ts'), indexLines.join('\n') + '\n') -} - -async function main(): Promise { - console.log('Loading English base...') - const en = await loadLocale('en') - const codes = Object.keys(LOCALE_FILE_MAP) - - // Clean existing locale dirs; leave hand-authored files (types.ts, languages.ts, index.ts) alone - await Promise.all(codes.map(code => rm(join(I18N_OUT, code), { recursive: true, force: true }))) - - for (const code of codes) { - process.stdout.write(`Processing ${code}...`) - let strings = await loadLocale(code) - - if (code === 'ar') { - // ar.ts spreads en — keep only keys that ar actually translates (value differs from en) - const pruned: LocaleStrings = {} - for (const [key, val] of Object.entries(strings)) { - if (JSON.stringify(val) !== JSON.stringify(en[key])) { - pruned[key] = val - } - } - strings = pruned - console.log(` ${Object.keys(strings).length} own keys (pruned from ${Object.keys(en).length} en total)`) - } else { - const nsCount = new Set(Object.keys(strings).map(k => k.split('.')[0])).size - console.log(` ${Object.keys(strings).length} keys, ${nsCount} namespaces`) - } - - await writeLocaleDir(code, strings) - } - - console.log('\nDone! Run: cd shared && npm run build') -} - -main().catch(err => { console.error(err); process.exit(1) })