性能优先原则 logo

性能优先原则

Organization
microwind
性能优先原则

在性能关键路径上,以性能为首要考量进行设计和优化,同时避免过早优化。

Overview

Publishermicrowind
Repositoryai-skills
Skill name性能优先原则
Stars
93
Forks
25
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by microwind on GitHub. Read the source before you install it.

Installation

Install the 性能优先原则 AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/microwind/ai-skills/tree/main/design-principles/performance-first-principle
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/microwind/ai-skills.git /tmp/ai-skills
mkdir -p .claude/skills
cp -r /tmp/ai-skills/design-principles/performance-first-principle .claude/skills/microwind-48
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable 性能优先原则 in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads 性能优先原则 on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so 性能优先原则 is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

性能优先原则 (Performance-First Principle)

概述

性能优先原则关注:在正确性之后,性能是系统最重要的质量属性之一。但要区分"性能意识"和"过早优化"。

核心思想:

  • "过早优化是万恶之源" —— Knuth(但不要忽视性能)
  • 先让代码正确,再让代码快
  • 用数据驱动优化决策,不要凭直觉
  • 性能瓶颈通常在 20% 的代码中

性能优化流程

1. 测量 → 2. 分析 → 3. 优化 → 4. 验证

❌ 错误流程:直觉 → 优化 → 期望变快
✅ 正确流程:Profiler → 找到热点 → 定向优化 → 基准测试确认

常见性能优化

数据库层

java
// ❌ N+1 查询问题
public List<OrderDTO> getOrders() {
    List<Order> orders = orderRepo.findAll();  // 1次查询
    return orders.stream().map(order -> {
        Customer c = customerRepo.findById(order.getCustomerId());  // N次查询
        return new OrderDTO(order, c);
    }).collect(toList());
}

// ✅ 批量查询
public List<OrderDTO> getOrders() {
    List<Order> orders = orderRepo.findAll();
    Set<Long> customerIds = orders.stream()
        .map(Order::getCustomerId).collect(toSet());
    Map<Long, Customer> customers = customerRepo.findByIds(customerIds)
        .stream().collect(toMap(Customer::getId, c -> c));
    return orders.stream()
        .map(o -> new OrderDTO(o, customers.get(o.getCustomerId())))
        .collect(toList());
}

缓存策略

python
# ✅ 合理使用缓存
from functools import lru_cache

@lru_cache(maxsize=1000)
def get_user_permissions(user_id: str) -> set:
    """频繁调用、结果稳定的查询适合缓存"""
    return permission_repo.find_by_user(user_id)

# 缓存原则
# 1. 读多写少的数据
# 2. 计算成本高的结果
# 3. 设置合理的过期时间
# 4. 数据变更时主动失效缓存

算法选择

java
// ❌ O(n²)
public boolean hasDuplicate(List<Integer> list) {
    for (int i = 0; i < list.size(); i++)
        for (int j = i + 1; j < list.size(); j++)
            if (list.get(i).equals(list.get(j))) return true;
    return false;
}

// ✅ O(n)
public boolean hasDuplicate(List<Integer> list) {
    return list.size() != new HashSet<>(list).size();
}

过早优化 vs 性能意识

✅ 性能意识(始终应该有):
- 选择合适的数据结构(HashMap vs LinkedList)
- 避免 N+1 查询
- 不在循环中创建不必要的对象
- 合理使用索引

❌ 过早优化(应该避免):
- 在没有性能问题时手写缓存
- 用位运算替代乘除法
- 为了"性能"牺牲可读性
- 在非瓶颈处花大量时间优化

性能检查清单

□ 数据库查询有合适的索引
□ 没有 N+1 查询问题
□ 大列表操作使用分页
□ 频繁访问的数据有缓存策略
□ API 有合理的超时设置
□ 文件/网络 I/O 使用异步或批处理
□ 有性能基准测试和监控

与其他原则的关系

原则关系
KISS简单的代码通常性能也不差
YAGNI不需要的优化不要做
关注点分离性能优化集中在瓶颈处

总结

核心:用数据驱动性能优化,优化瓶颈而非猜测。

实践:先正确 → 再测量 → 再优化 → 再验证。

Frequently asked questions

What does the 性能优先原则 AI skill do?

在性能关键路径上,以性能为首要考量进行设计和优化,同时避免过早优化。

Why use 性能优先原则 on TypingMind?

Because you install it once and use it with any model. 性能优先原则 is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install 性能优先原则 in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/microwind/ai-skills/tree/main/design-principles/performance-first-principle. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use 性能优先原则?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with 性能优先原则?

As many as you like. As long as a model supports skills, you can use 性能优先原则 with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the 性能优先原则 AI skill free?

Yes. It is published on GitHub by microwind under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇