[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6F3JNQ9QS7XG09SDXHFZSWY":3,"skill-same:01M6F3JNQ9QS7XG09SDXHFZSWY":69},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":46,"commitSha":47,"skillDirectory":48,"forksCount":49,"repositoryHtmlUrl":50,"repositoryHomepageUrl":51,"ownerHtmlUrl":52,"ownerBlogUrl":6,"ownerDescription":53,"updatedAt":54,"install":55,"resources":68},"01M6F3JNQ9QS7XG09SDXHFZSWY","go-performance",null,"Use when optimizing Go code, investigating slow performance, or writing performance-critical sections. Also use when a user mentions slow Go code, string concatenation in loops, or asks about benchmarking, even if the user doesn't explicitly mention performance patterns. Does not cover concurrent performance patterns (see go-concurrency).","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fcxuu\u002Fgolang-skills\u002Fgo-performance\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"go performance","go","performance","user","about","loops","STRING","style","critical","patterns","use","guide","writing","wiki","Bash","concurrency","code","benchmarking","google","2026-11-10 10:12:30",false,"---\nname: go-performance\ndescription: Use when optimizing Go code, investigating slow performance, or writing performance-critical sections. Also use when a user mentions slow Go code, string concatenation in loops, or asks about benchmarking, even if the user doesn't explicitly mention performance patterns. Does not cover concurrent performance patterns (see go-concurrency).\nlicense: Apache-2.0\nmetadata:\n  sources: \"Uber Style Guide, Google Style Guide, Go Wiki CodeReviewComments\"\nallowed-tools: Bash(bash:*)\n---\n\n# Go Performance Patterns\n\n## Available Scripts\n\n- **`scripts\u002Fbench-compare.sh`** — Runs Go benchmarks N times with optional baseline comparison via benchstat. Supports saving results for future comparison. Run `bash scripts\u002Fbench-compare.sh --help` for options.\n\nPerformance-specific guidelines apply only to the **hot path**. Don't prematurely optimize—focus these patterns where they matter most.\n\n---\n\n## Prefer strconv over fmt\n\nWhen converting primitives to\u002Ffrom strings, `strconv` is faster than `fmt`:\n\n```go\ns := strconv.Itoa(rand.Int()) \u002F\u002F ~2x faster than fmt.Sprint()\n```\n\n| Approach | Speed | Allocations |\n|----------|-------|-------------|\n| `fmt.Sprint` | 143 ns\u002Fop | 2 allocs\u002Fop |\n| `strconv.Itoa` | 64.2 ns\u002Fop | 1 allocs\u002Fop |\n\n> Read [references\u002FSTRING-OPTIMIZATION.md](references\u002FSTRING-OPTIMIZATION.md) when choosing between strconv and fmt for type conversions, or for the full conversion table.\n\n---\n\n## Avoid Repeated String-to-Byte Conversions\n\nConvert a fixed string to `[]byte` once outside the loop:\n\n```go\ndata := []byte(\"Hello world\")\nfor i := 0; i \u003C b.N; i++ {\n    w.Write(data) \u002F\u002F ~7x faster than []byte(\"...\") each iteration\n}\n```\n\n> Read [references\u002FSTRING-OPTIMIZATION.md](references\u002FSTRING-OPTIMIZATION.md) when optimizing repeated byte conversions in hot loops.\n\n---\n\n## Prefer Specifying Container Capacity\n\nSpecify container capacity where possible to allocate memory up front. This minimizes subsequent allocations from copying and resizing as elements are added.\n\n### Map Capacity Hints\n\nProvide capacity hints when initializing maps with `make()`:\n\n```go\nm := make(map[string]os.DirEntry, len(files))\n```\n\n**Note**: Unlike slices, map capacity hints do not guarantee complete preemptive allocation—they approximate the number of hashmap buckets required.\n\n### Slice Capacity\n\nProvide capacity hints when initializing slices with `make()`, particularly when appending:\n\n```go\ndata := make([]int, 0, size)\n```\n\nUnlike maps, slice capacity is **not a hint**—the compiler allocates exactly that much memory. Subsequent `append()` operations incur zero allocations until capacity is reached.\n\n| Approach | Time (100M iterations) |\n|----------|------------------------|\n| No capacity | 2.48s |\n| With capacity | 0.21s |\n\nThe capacity version is **~12x faster** due to zero reallocations during append.\n\n---\n\n## Pass Values\n\nDon't pass pointers as function arguments just to save a few bytes. If a function refers to its argument `x` only as `*x` throughout, then the argument shouldn't be a pointer.\n\n```go\nfunc process(s string) { \u002F\u002F not *string — strings are small fixed-size headers\n    fmt.Println(s)\n}\n```\n\n**Common pass-by-value types**: `string`, `io.Reader`, small structs.\n\n**Exceptions**:\n- Large structs where copying is expensive\n- Small structs that might grow in the future\n\n---\n\n## String Concatenation\n\nChoose the right strategy based on complexity:\n\n| Method | Best For |\n|--------|----------|\n| `+` | Few strings, simple concat |\n| `fmt.Sprintf` | Formatted output with mixed types |\n| `strings.Builder` | Loop\u002Fpiecemeal construction |\n| `strings.Join` | Joining a slice |\n| Backtick literal | Constant multi-line text |\n\n> Read [references\u002FSTRING-OPTIMIZATION.md](references\u002FSTRING-OPTIMIZATION.md) when choosing a string concatenation strategy, using strings.Builder in loops, or deciding between fmt.Sprintf and manual concatenation.\n\n---\n\n## Benchmarking and Profiling\n\nAlways measure before and after optimizing. Use Go's built-in benchmark framework and profiling tools.\n\n```bash\ngo test -bench=. -benchmem -count=10 .\u002F...\n```\n\n> Read [references\u002FBENCHMARKS.md](references\u002FBENCHMARKS.md) when writing benchmarks, comparing results with benchstat, profiling with pprof, or interpreting benchmark output.\n\n> **Validation**: After applying optimizations, run `bash scripts\u002Fbench-compare.sh` to measure the actual impact. Only keep optimizations with measurable improvement.\n\n---\n\n## Quick Reference\n\n| Pattern | Bad | Good | Improvement |\n|---------|-----|------|-------------|\n| Int to string | `fmt.Sprint(n)` | `strconv.Itoa(n)` | ~2x faster |\n| Repeated `[]byte` | `[]byte(\"str\")` in loop | Convert once outside | ~7x faster |\n| Map initialization | `make(map[K]V)` | `make(map[K]V, size)` | Fewer allocs |\n| Slice initialization | `make([]T, 0)` | `make([]T, 0, cap)` | ~12x faster |\n| Small fixed-size args | `*string`, `*io.Reader` | `string`, `io.Reader` | No indirection |\n| Simple string join | `s1 + \" \" + s2` | (already good) | Use `+` for few strings |\n| Loop string build | Repeated `+=` | `strings.Builder` | O(n) vs O(n²) |\n\n---\n\n## Related Skills\n\n- **Data structures**: See [go-data-structures](..\u002Fgo-data-structures\u002FSKILL.md) when choosing between slices, maps, and arrays, or understanding allocation semantics\n- **Declaration patterns**: See [go-declarations](..\u002Fgo-declarations\u002FSKILL.md) when using `make` with capacity hints or initializing maps and slices\n- **Concurrency**: See [go-concurrency](..\u002Fgo-concurrency\u002FSKILL.md) when parallelizing work across goroutines or using sync.Pool for buffer reuse\n- **Style principles**: See [go-style-core](..\u002Fgo-style-core\u002FSKILL.md) when deciding whether an optimization is worth the readability cost\n\n","# Go Performance Patterns\n\n## Available Scripts\n\n- **`scripts\u002Fbench-compare.sh`** — Runs Go benchmarks N times with optional baseline comparison via benchstat. Supports saving results for future comparison. Run `bash scripts\u002Fbench-compare.sh --help` for options.\n\nPerformance-specific guidelines apply only to the **hot path**. Don't prematurely optimize—focus these patterns where they matter most.\n\n---\n\n## Prefer strconv over fmt\n\nWhen converting primitives to\u002Ffrom strings, `strconv` is faster than `fmt`:\n\n```go\ns := strconv.Itoa(rand.Int()) \u002F\u002F ~2x faster than fmt.Sprint()\n```\n\n| Approach | Speed | Allocations |\n|----------|-------|-------------|\n| `fmt.Sprint` | 143 ns\u002Fop | 2 allocs\u002Fop |\n| `strconv.Itoa` | 64.2 ns\u002Fop | 1 allocs\u002Fop |\n\n> Read [references\u002FSTRING-OPTIMIZATION.md](references\u002FSTRING-OPTIMIZATION.md) when choosing between strconv and fmt for type conversions, or for the full conversion table.\n\n---\n\n## Avoid Repeated String-to-Byte Conversions\n\nConvert a fixed string to `[]byte` once outside the loop:\n\n```go\ndata := []byte(\"Hello world\")\nfor i := 0; i \u003C b.N; i++ {\n    w.Write(data) \u002F\u002F ~7x faster than []byte(\"...\") each iteration\n}\n```\n\n> Read [references\u002FSTRING-OPTIMIZATION.md](references\u002FSTRING-OPTIMIZATION.md) when optimizing repeated byte conversions in hot loops.\n\n---\n\n## Prefer Specifying Container Capacity\n\nSpecify container capacity where possible to allocate memory up front. This minimizes subsequent allocations from copying and resizing as elements are added.\n\n### Map Capacity Hints\n\nProvide capacity hints when initializing maps with `make()`:\n\n```go\nm := make(map[string]os.DirEntry, len(files))\n```\n\n**Note**: Unlike slices, map capacity hints do not guarantee complete preemptive allocation—they approximate the number of hashmap buckets required.\n\n### Slice Capacity\n\nProvide capacity hints when initializing slices with `make()`, particularly when appending:\n\n```go\ndata := make([]int, 0, size)\n```\n\nUnlike maps, slice capacity is **not a hint**—the compiler allocates exactly that much memory. Subsequent `append()` operations incur zero allocations until capacity is reached.\n\n| Approach | Time (100M iterations) |\n|----------|------------------------|\n| No capacity | 2.48s |\n| With capacity | 0.21s |\n\nThe capacity version is **~12x faster** due to zero reallocations during append.\n\n---\n\n## Pass Values\n\nDon't pass pointers as function arguments just to save a few bytes. If a function refers to its argument `x` only as `*x` throughout, then the argument shouldn't be a pointer.\n\n```go\nfunc process(s string) { \u002F\u002F not *string — strings are small fixed-size headers\n    fmt.Println(s)\n}\n```\n\n**Common pass-by-value types**: `string`, `io.Reader`, small structs.\n\n**Exceptions**:\n- Large structs where copying is expensive\n- Small structs that might grow in the future\n\n---\n\n## String Concatenation\n\nChoose the right strategy based on complexity:\n\n| Method | Best For |\n|--------|----------|\n| `+` | Few strings, simple concat |\n| `fmt.Sprintf` | Formatted output with mixed types |\n| `strings.Builder` | Loop\u002Fpiecemeal construction |\n| `strings.Join` | Joining a slice |\n| Backtick literal | Constant multi-line text |\n\n> Read [references\u002FSTRING-OPTIMIZATION.md](references\u002FSTRING-OPTIMIZATION.md) when choosing a string concatenation strategy, using strings.Builder in loops, or deciding between fmt.Sprintf and manual concatenation.\n\n---\n\n## Benchmarking and Profiling\n\nAlways measure before and after optimizing. Use Go's built-in benchmark framework and profiling tools.\n\n```bash\ngo test -bench=. -benchmem -count=10 .\u002F...\n```\n\n> Read [references\u002FBENCHMARKS.md](references\u002FBENCHMARKS.md) when writing benchmarks, comparing results with benchstat, profiling with pprof, or interpreting benchmark output.\n\n> **Validation**: After applying optimizations, run `bash scripts\u002Fbench-compare.sh` to measure the actual impact. Only keep optimizations with measurable improvement.\n\n---\n\n## Quick Reference\n\n| Pattern | Bad | Good | Improvement |\n|---------|-----|------|-------------|\n| Int to string | `fmt.Sprint(n)` | `strconv.Itoa(n)` | ~2x faster |\n| Repeated `[]byte` | `[]byte(\"str\")` in loop | Convert once outside | ~7x faster |\n| Map initialization | `make(map[K]V)` | `make(map[K]V, size)` | Fewer allocs |\n| Slice initialization | `make([]T, 0)` | `make([]T, 0, cap)` | ~12x faster |\n| Small fixed-size args | `*string`, `*io.Reader` | `string`, `io.Reader` | No indirection |\n| Simple string join | `s1 + \" \" + s2` | (already good) | Use `+` for few strings |\n| Loop string build | Repeated `+=` | `strings.Builder` | O(n) vs O(n²) |\n\n---\n\n## Related Skills\n\n- **Data structures**: See [go-data-structures](..\u002Fgo-data-structures\u002FSKILL.md) when choosing between slices, maps, and arrays, or understanding allocation semantics\n- **Declaration patterns**: See [go-declarations](..\u002Fgo-declarations\u002FSKILL.md) when using `make` with capacity hints or initializing maps and slices\n- **Concurrency**: See [go-concurrency](..\u002Fgo-concurrency\u002FSKILL.md) when parallelizing work across goroutines or using sync.Pool for buffer reuse\n- **Style principles**: See [go-style-core](..\u002Fgo-style-core\u002FSKILL.md) when deciding whether an optimization is worth the readability cost\n\n",{"name":5,"license":15,"metadata":43,"description":7,"allowed-tools":45},{"sources":44},"Uber Style Guide, Google Style Guide, Go Wiki CodeReviewComments","Bash(bash:*)","main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Fcxuu\u002Fgolang-skills\u002Fgo-performance",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":56,"prompt":66,"zipAvailable":67},[57,60,63],{"tool":58,"command":59},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill go-performance",{"tool":61,"command":62},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill go-performance",{"tool":64,"command":65},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill go-performance","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fcxuu\u002Fgolang-skills\u002Fgo-performance\u002FSKILL.md",true,[],[70,80,89,98,104,110],{"skillNo":71,"name":72,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":73,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":38},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[77,78,79],"model","model hierarchy","model hierarchy skill",{"skillNo":81,"name":82,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":73,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":38},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[86,87,88],"MCP","zoom","zoom mcp",{"skillNo":90,"name":91,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":73,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":38},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[95,96,97,87],"sdk","zoom apps sdk","apps",{"skillNo":99,"name":100,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":73,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":103,"publishedAt":38},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[100],{"skillNo":105,"name":106,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":73,"licenseFileUrl":6,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":38},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[106],{"skillNo":111,"name":112,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":73,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":38},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[112]]