用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/hacan359/tonkatsu_box --skill optimize命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | optimize |
| description | Code optimization for performance, memory, and readability. Use to improve existing code. |
# Flutter SDK lives on Windows — run via powershell.exe from WSL:
powershell.exe -Command "cd '$(wslpath -w "$PWD")'; flutter run -d windows --profile"
# Open DevTools and analyze:
# - CPU Profiler
# - Memory
# - Performance overlay
| Before | After | Example |
|---|---|---|
| O(n²) | O(n log n) | Sorting |
| O(n²) | O(n) | Nested loops → Map/Set |
| O(n) | O(1) | Linear search → HashMap |
// BAD: O(n²)
for (final item in list1) {
if (list2.contains(item)) { ... }
}
// GOOD: O(n)
final set2 = list2.toSet();
for (final item in list1) {
if (set2.contains(item)) { ... }
}
// Reuse objects
final _dateFormat = DateFormat('yyyy-MM-dd'); // Once
// Use const
const _defaultPadding = EdgeInsets.all(16);
// Unsubscribe in dispose
@override
void dispose() {
_subscription.cancel();
_controller.dispose();
super.dispose();
}
// BAD: entire list rebuilds
ListView(
children: items.map((i) => ItemWidget(i)).toList(),
)
// GOOD: only visible items
ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) => ItemWidget(items[index]),
)
// BAD
return Container(
padding: EdgeInsets.all(16), // Created every build
child: Text('Hello'),
);
// GOOD
return const Padding(
padding: EdgeInsets.all(16),
child: Text('Hello'),
);
// BAD: entire widget rebuilds when counter changes
class MyWidget extends StatefulWidget {
Widget build(context) {
return Column(
children: [
Text('Counter: $counter'), // Changes
HeavyWidget(), // Doesn't change but rebuilds
],
);
}
}
// GOOD: extract immutable parts
class MyWidget extends StatefulWidget {
Widget build(context) {
return Column(
children: [
CounterText(counter: counter),
const HeavyWidget(), // Doesn't rebuild
],
);
}
}
// BAD: sequential
final users = await fetchUsers();
final posts = await fetchPosts();
// GOOD: parallel
final results = await Future.wait([
fetchUsers(),
fetchPosts(),
]);
class CachedRepository {
final Map<String, User> _cache = {};
Future<User> getUser(String id) async {
if (_cache.containsKey(id)) {
return _cache[id]!;
}
final user = await _api.fetchUser(id);
_cache[id] = user;
return user;
}
}
Timer? _debounce;
void onSearchChanged(String query) {
_debounce?.cancel();
_debounce = Timer(const Duration(milliseconds: 300), () {
performSearch(query);
});
}
After optimization:
# Verify nothing is broken (Flutter SDK is on Windows only):
powershell.exe -Command "cd '$(wslpath -w "$PWD")'; flutter analyze --fatal-infos --fatal-warnings"
powershell.exe -Command "cd '$(wslpath -w "$PWD")'; flutter test"
# Check performance:
powershell.exe -Command "cd '$(wslpath -w "$PWD")'; flutter run -d windows --profile"
# Use Performance overlay (P in console)