go-performance

go-performance is a cursor rule for Cursor from wangqiqi/cursor-ai-rules. It costs 0 tokens per session (1,552 once invoked), scanned A, original, MIT.

A collection of guidance for making Go programs use less CPU and memory and handle concurrent work safely. Go is a programming language with built-in support for running tasks at the same time.

In plain words
What is it for?
Use it when working on Go performance, including atomic counters, worker pools, input validation, memory use, CPU use, and concurrency.
Why use it?
It helps developers identify and apply common approaches for improving runtime efficiency and managing concurrent code.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/wangqiqi/cursor-ai-rules/go-performance
Clone the repo
git clone --depth 1 https://github.com/wangqiqi/cursor-ai-rules

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for go-performance

README.md
[![agentmods](https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/go-performance.svg)](https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/go-performance)
Your own site
<a href="https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/go-performance"><img src="https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/go-performance.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,552 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01552
Opus 5 $0.00000 $0.00776
Sonnet 5 $0.00000 $0.00310
Haiku 4.5 $0.00000 $0.00155

Measured 4d ago against content hash 09494da2819e, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

go-performance scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/tech/go-performance.mdc · 260 lines

How it starts

The opening of the file, as written. The whole thing — 260 lines — stays where its author put it; the contents beside it link to each section on GitHub.

🚀 Go 性能优化

type AtomicCounter struct { count int64 }

func (c *AtomicCounter) Increment() { atomic.AddInt64(&c.count, 1) }

func (c *AtomicCounter) Get() int64 { return atomic.LoadInt64(&c.count) }

// ✅ 推荐:Worker Pool 模式 type WorkerPool struct { workers int taskChan chan func() quitChan chan struct{} wg sync.WaitGroup }

func NewWorkerPool(workers int) WorkerPool { wp := &WorkerPool{ workers: workers, taskChan: make(chan func(), workers2), quitChan: make(chan struct{}), }

wp.start()
return wp

}

func (wp *WorkerPool) start() { for i := 0; i < wp.workers; i++ { wp.wg.Add(1) go func() { defer wp.wg.Done() for { select { case task := <-wp.taskChan: task() case <-wp.quitChan: return } } }() } }

func (wp *WorkerPool) Submit(task func()) { select { case wp.taskChan <- task: case <-wp.quitChan: return } }

func (wp *WorkerPool) Stop() { close(wp.quitChan) wp.wg.Wait() }


## 🔒 安全实践

### 输入验证和清理
```go
import (
    "html"
    "net/url"
    "regexp"
    "strings"
    "unicode/utf8"
)

// ✅ 推荐:输入验证和清理
type UserInputValidator struct {
    usernameRegex *regexp.Regexp
    emailRegex    *regexp.Regexp
}

func NewUserInputValidator() *UserInputValidator {
    return &UserInputValidator{
        usernameRegex: regexp.MustCompile(`^[a-zA-Z0-9_]{3,50}$`),
        emailRegex:    regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`),
    }
}

func (v *UserInputValidator) ValidateUsername(username string) error {
    if username == "" {
        return errors.New("username is required")
    }

    if utf8.RuneCountInString(username) > 50 {
        return errors.New("username too long")
    }

    if !v.usernameRegex.MatchString(username) {
        return errors.New("username contains invalid characters")
    }

    return nil
}

func (v *UserInputValidator) ValidateEmail(email string) error {
    if email == "" {
        return errors.New("email is required")
    }

    if len(email) > 254 {
        return errors.New("email too long")
    }

    email = strings.TrimSpace(strings.ToLower(email))

    if !v.emailRegex.MatchString(email) {
        return errors.New("invalid email format")
    }

    return nil
}

func (v *UserInputValidator) SanitizeInput(input string) string {
    // HTML转义
    input = html.EscapeString(input)

    // URL编码处理
    if strings.Contains(input, "%") {
        if decoded, err := url.QueryUnescape(input); err == nil {
            input = decoded
        }
    }

    // 移除控制字符
    input = strings.Map(func(r rune) rune {
        if r < 32 || r == 127 {
            return -1
        }
        return r
    }, input)

    return strings.TrimSpace(input)
}

// ✅ 推荐:SQL注入防护
func (r *UserRepository) GetUserByIDSafe(ctx context.Context, id int64) (*User, error) {
    // 使用参数化查询自动防止SQL注入
    query := `SELECT id, username, email, created_at FROM users WHERE id = $1`

    var user User
    err := r.db.QueryRowContext(ctx, query, id).Scan(
        &user.ID, &user.Username, &user.Email, &user.CreatedAt,
    )

    if err == sql.ErrNoRows {
        return nil, ErrUserNotFound
    }
    if err != nil {
        return nil, fmt.Errorf("failed to get user: %w", err)
    }

    return &user, nil
}

密码安全处理

import (
    "crypto/rand"
    "crypto/subtle"
    "golang.org/x/crypto/argon2"
    "golang.org/x/crypto/bcrypt"
)

// ✅ 推荐:安全的密码哈希
type PasswordHasher struct {
    time    uint32
    memory  uint32
    threads uint8
    keyLen  uint32
}

func NewPasswordHasher() *PasswordHasher {
    return &PasswordHasher{
        time:    1,
        memory:  64 * 1024, // 64MB
        threads: 4,
        keyLen:  32,
    }
}

func (h *PasswordHasher) HashPassword(password string) ([]byte, error) {
    // 生成盐值
    salt := make([]byte, 32)
    if _, err := rand.Read(salt); err != nil {
        return nil, err
    }

Read the full file on GitHub · 260 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 260 lines · 0 tokens per session scan A 09494da2819e

Subscribe to this mod's changes

go-performance is a cursor rule published in the GitHub repository wangqiqi/cursor-ai-rules (15 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,552 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.