Skip to content

Commit 31c2e67

Browse files
committed
🔀 merge: 性能与模块化优化方案(7 阶段 24 任务全部完成)
合并 feature/perf-modular-optimization(39 commits / 176 files) 性能基线对比(brotli): - entry: 72 KB → 25.14 KB(-65%) - vendor: 1.27 MB → 58.38 KB(-95%) - game-runtime: 636 KB → 377 KB(-41%) - entry raw: 326 KB → 100 KB(-69%) 关键产出: - vite manualChunks 拆 6 块 vendor + 5 块 game-runtime + 5 块 settings - 异步 NSFW 注册(按 gameConfig 激活,修复原配置路径错误) - useGame 130 文件领域重组 + 6 Zustand slice 骨架 + FACADE.md - 路由级 code splitting(Landing/NewGame/Game 三视图独立) - js-tiktoken 移除(节省 1.19 MB brotli) - size-limit + Lighthouse CI 双层防护 - 155 个 feature flag 全面盘点 参考:docs/technical/13b-performance-modularization.md
2 parents 8f24f8b + 5f24fa9 commit 31c2e67

178 files changed

Lines changed: 2753 additions & 2866 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ on:
77
branches: [main]
88

99
jobs:
10+
build:
11+
name: Build & Bundle Size
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 15
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Build
29+
run: npm run build
30+
31+
- name: Check bundle size (size-limit)
32+
run: npm run size
33+
1034
vitest:
1135
name: Unit Tests (Vitest)
1236
runs-on: ubuntu-latest

.github/workflows/lighthouse.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Lighthouse CI
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
push:
7+
branches: [main]
8+
9+
jobs:
10+
lighthouse:
11+
name: Lighthouse Performance Audit
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 15
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 20
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Build
29+
run: npm run build
30+
31+
- name: Run Lighthouse CI
32+
run: npx lhci autorun
33+
env:
34+
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Dependencies
22
/node_modules/
3+
**/node_modules/
34

45
# Build outputs
56
/dist/
@@ -28,7 +29,9 @@ pnpm-debug.log*
2829
lerna-debug.log*
2930

3031
# Generated reports, temp workspaces, and local analysis outputs
31-
/artifacts/
32+
/artifacts/*
33+
!/artifacts/baseline-*.json
34+
!/artifacts/build-*.txt
3235
/.tmp*/
3336
/clean_diff.txt
3437
/diff.txt

App.tsx

Lines changed: 131 additions & 101 deletions
Large diffs are not rendered by default.

artifacts/baseline-2026-06-04.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"metadata": {
3+
"collectedAt": "2026-06-04T08:42:54.270Z",
4+
"phase": "0.3",
5+
"branch": "feature/perf-modular-optimization",
6+
"script": "node scripts/collectMetricsBaseline.mjs",
7+
"command": "npm run metrics:baseline",
8+
"supplementalCommands": [
9+
"npm run size",
10+
"find . -type f \\( -name '*.ts' -o -name '*.tsx' \\) [excludes]"
11+
]
12+
},
13+
"bundle": {
14+
"source": "size-limit (npm run size)",
15+
"entry": {
16+
"sizeLimit": "350 kB",
17+
"size": "72.03 kB",
18+
"loadingTime": "1.5 s on slow 3G",
19+
"runningTime": "48 ms on Snapdragon 410"
20+
},
21+
"vendor": {
22+
"sizeLimit": "3.7 MB",
23+
"size": "1.27 MB",
24+
"loadingTime": "24.9 s on slow 3G",
25+
"runningTime": "112 ms on Snapdragon 410"
26+
},
27+
"gameRuntime": {
28+
"sizeLimit": "3 MB",
29+
"size": "636.56 kB",
30+
"loadingTime": "12.5 s on slow 3G",
31+
"runningTime": "81 ms on Snapdragon 410"
32+
}
33+
},
34+
"codeStats": {
35+
"tsTsxFileCount": 2916,
36+
"tsTsxLineCount": 1020698,
37+
"note": "Includes all .ts/.tsx under project root, excluding node_modules/.git/dist/coverage/.tmp"
38+
},
39+
"circularDependencies": {
40+
"tool": "madge",
41+
"filesProcessed": 1501,
42+
"circularCount": 15,
43+
"warnings": 74,
44+
"ok": false,
45+
"exitCode": 1,
46+
"detailsFile": ".tmp/baseline-circular.txt"
47+
},
48+
"deadExports": {
49+
"tool": "ts-prune",
50+
"deadExportCount": 5615,
51+
"ok": true,
52+
"exitCode": 0,
53+
"detailsFile": ".tmp/baseline-dead.txt"
54+
},
55+
"unusedCode": {
56+
"tool": "knip",
57+
"unusedFiles": 420,
58+
"unusedExports": 1415,
59+
"unusedExportedTypes": 1032,
60+
"unusedDevDependencies": 5,
61+
"unusedDevDependenciesList": [
62+
"@alloc/quick-lru",
63+
"@testing-library/jest-dom",
64+
"ast-grep",
65+
"depcheck",
66+
"tslib"
67+
],
68+
"unlistedBinaries": 1,
69+
"unlistedBinariesList": [
70+
"wrangler (.github/workflows/deploy.yml)"
71+
],
72+
"ok": false,
73+
"exitCode": 1,
74+
"detailsFile": ".tmp/baseline-unused.txt"
75+
},
76+
"tests": {
77+
"tool": "vitest run + manual glob",
78+
"testFiles": 96,
79+
"testCases": 2137,
80+
"vitestResult": {
81+
"testFilesPassed": 96,
82+
"testsPassed": 2149,
83+
"duration": "69.27s"
84+
},
85+
"ok": true,
86+
"exitCode": 0,
87+
"detailsFile": ".tmp/baseline-tests.txt"
88+
},
89+
"summary": {
90+
"totalSteps": 5,
91+
"okSteps": 3,
92+
"failSteps": 2,
93+
"failSoftTools": ["madge", "knip"],
94+
"notes": "Script uses fail-soft: madge and knip exited non-zero but their raw output is captured for review. Follow-up phases can decide whether to remediate or document the failures."
95+
}
96+
}

artifacts/build-2026-06-04.txt

Lines changed: 171 additions & 0 deletions
Large diffs are not rendered by default.

components/app/GameView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { GalgameView } from './GalgameView';
1616
import { MobileGalgameView } from '../features/Galgame/mobile/MobileGalgameView';
1717
import { 懒加载边界, MobileMusicPlayer } from '../features/lazyComponents';
1818
import { useGalgameEngine } from '../../hooks/useGalgameEngine';
19-
import { getCurrentMode, switchMode } from '../../hooks/useGame/modeManager';
19+
import { getCurrentMode, switchMode } from '../../hooks/useGame/engine/modeManager';
2020

2121
// ============================================================================
2222
// 类型

components/features/Battle/BattleActionPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
执行战斗行动,
77
战斗行动选项,
88
战斗行动结果,
9-
} from '../../../hooks/useGame/combatCalculation';
9+
} from '../../../hooks/useGame/combat/combatCalculation';
1010
import { IconSwords, IconShield, IconPotion } from '../../ui/Icons';
1111

1212
interface Props {

components/features/Battle/BattleModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { 角色数据结构, 战斗状态结构 } from '../../../types';
33
import { IconSwords, IconYinYang } from '../../ui/Icons';
44
import BattleActionPanel from './BattleActionPanel';
55
import { RpgBattleIntegration, shouldUseRpgBattle } from './RpgBattleIntegration';
6-
import { 战斗行动结果 } from '../../../hooks/useGame/combatCalculation';
6+
import { 战斗行动结果 } from '../../../hooks/useGame/combat/combatCalculation';
77

88
interface Props {
99
character: 角色数据结构;

components/features/MobileDevice/apps/CampusForumApp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { 论坛帖子 } from '../../../../models/campusPhone';
55
import type { BDSM论坛帖子, BDSM帖子分类, 联系对话, 联系状态 } from '../../../../models/campusNSFW/bdsm-forum';
66
import type { NPC结构 } from '../../../../models/social';
77
import type { 当前可用接口结构 } from '../../../../utils/apiConfig';
8-
import { 从BDSM帖子创建NPC } from '../../../../hooks/useGame/bdsmForumEngine';
8+
import { 从BDSM帖子创建NPC } from '../../../../hooks/useGame/nsfw/bdsmForumEngine';
99
import BDSMContactModal from './BDSMContactModal';
1010

1111
type ApiConfigLike = 当前可用接口结构 | Record<string, unknown>;

0 commit comments

Comments
 (0)