agentleFS
saisudhir14saisudhir14/claude-skills/skills/go-performance/SKILL.md

go-performance

Skill9 starsChanged 8 months agoMITView on GitHub

Use when writing, reviewing, or optimizing Go code for performance. Covers string operations, memory allocation, preallocating slices and maps, strings.Builder, strconv, container-aware GOMAXPROCS, and runtime considerations for Go 1.25.

3 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions3 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 3

    1. cxuu/golang-skills★ 165same name
    2. muratmirgun/gophers★ 9same name
    3. Dankosik/golang-backend-skills★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository8 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefer runtime.AddCleanup over runtime.SetFinalizer for cleanup operations.

    line 111
  2. Distinctive:

    Use cases: caches, canonicalization maps, observer patterns.

    line 154

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Go Performance

Performance optimization patterns for production Go.

Prefer strconv Over fmt

strconv is faster for primitive conversions.

// Slower
s := fmt.Sprintf("%d", n)

// Faster
s := strconv.Itoa(n)

Avoid Repeated String to Byte Conversions

// Wrong: converts on every iteration
for i := 0; i < n; i++ {
    w.Write([]byte("hello"))
}

// Correct
data := []byte("hello")
for i := 0; i < n; i++ {
    w.Write(data)
}

Specify Map Capacity

// Wrong
m := make(map[string]int)

// Correct when size is known
m := make(map[string]int, len(items))

Preallocate Slice Capacity

// Wrong
var result []Item
for _, v := range input {
    result = append(result, transform(v))
}

// Correct
result := make([]Item, 0, len(input))
for _, v := range input {
    result = append(result, transform(v))
}

Use strings.Builder for Concatenation

// Wrong: creates many allocations
var s string
for _, part := range parts {
    s += part
}

// Correct
var b strings.Builder
b.Grow(totalLen) // optional: preallocate
for _, part := range parts {
    b.WriteString(part)
}
s := b.String()

Container-Aware GOMAXPROCS (Go 1.25+)

Go 1.25 automatically adjusts GOMAXPROCS based on container CPU limits.

// On Linux with cgroups, GOMAXPROCS now considers:
// - CPU bandwidth limits (CPU limit in Kubernetes)
// - Changes dynamically if limits change

// Automatic behavior is disabled if you set GOMAXPROCS explicitly:
// - Via GOMAXPROCS environment variable
// - Via runtime.GOMAXPROCS() call

This means Go programs in containers perform better out-of-the-box without manual GOMAXPROCS tuning.

Resource Management (Go 1.24+)

runtime.AddCleanup

Prefer runtime.AddCleanup over runtime.SetFinalizer for cleanup operations.

func NewResource() *Resource {
    r := &Resource{handle: allocHandle()}
    runtime.AddCleanup(r, func(handle uintptr) {
        freeHandle(handle)
    }, r.handle)
    return r
}

Advantages over SetFinalizer:

  • Multiple cleanups per object
  • Works with interior pointers
  • No cycle-related leaks
  • Object freed promptly (single GC cycle)

Weak Pointers (Go 1.24+)

The weak package provides weak references that don't prevent garbage collection.

import "weak"

type Cache struct {
    mu    sync.Mutex
    items map[string]weak.Pointer[ExpensiveResource]
}

func (c *Cache) Get(key string) *ExpensiveResource {
    c.mu.Lock()
    defer c.mu.Unlock()
    if wp, ok := c.items[key]; ok {
        if r := wp.Value(); r != nil {
            return r
        }
        delete(c.items, key)
    }
    return nil
}

Use cases: caches, canonicalization maps, observer patterns.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.