Comprehensive performance optimization guide for Ruby applications, maintained by the community. Contains 42 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
Writing new Ruby code or gems
Optimizing ActiveRecord queries and database access patterns
Processing large collections or building data pipelines
str-shovel-over-plus - Use Shovel Operator for String Building
str-interpolation-over-concatenation - Use String Interpolation Over Concatenation
str-avoid-repeated-gsub - Chain gsub Calls into a Single Replacement
str-symbol-for-identifiers - Use Symbols for Identifiers and Hash Keys
5. Method & Dispatch (MEDIUM-HIGH)
meth-avoid-method-missing-hot-paths - Avoid method_missing in Hot Paths
meth-cache-method-references - Cache Method References for Repeated Calls
meth-block-vs-proc - Pass Blocks Directly Instead of Converting to Proc
meth-avoid-dynamic-send - Avoid Dynamic send in Performance-Critical Code
meth-reduce-method-chain-depth - Reduce Method Chain Depth in Hot Loops
6. Data Structures (MEDIUM)
ds-set-for-membership - Use Set for Membership Tests
ds-struct-over-openstruct - Use Struct Over OpenStruct
ds-sort-by-over-sort - Use sort_by Instead of sort with Block
ds-array-preallocation - Preallocate Arrays When Size Is Known
ds-hash-default-value - Use Hash Default Values Instead of Conditional Assignment
7. Concurrency (MEDIUM)
conc-fiber-for-io - Use Fibers for I/O-Bound Concurrency
conc-thread-pool-sizing - Size Thread Pools to Match Workload
conc-ractor-cpu-bound - Use Ractors for CPU-Bound Parallelism
conc-avoid-shared-mutable-state - Avoid Shared Mutable State Between Threads
8. Runtime & Configuration (LOW-MEDIUM)
runtime-enable-yjit - Enable YJIT for Production
runtime-tune-gc-parameters - Tune GC Parameters for Your Workload
runtime-frozen-string-literal-default - Set Frozen String Literal as Project Default
runtime-optimize-require - Optimize Require Load Order
How to Use
Read individual reference files for detailed explanations and code examples:
Section definitions - Category structure and impact levels
Rule template - Template for adding new rules
Reference Files
File
Description
references/_sections.md
Category definitions and ordering
assets/templates/_template.md
Template for new rules
metadata.json
Version and reference information
1---2name: ruby-optimise3description: Community Ruby Best Practices4---5# Community Ruby Best Practices67Comprehensive performance optimization guide for Ruby applications, maintained by the community. Contains 42 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.89## When to Apply1011Reference these guidelines when:12- Writing new Ruby code or gems13- Optimizing ActiveRecord queries and database access patterns14- Processing large collections or building data pipelines15- Reviewing code for memory bloat and GC pressure16- Configuring Ruby runtime settings for production1718## Rule Categories by Priority1920| Priority | Category | Impact | Prefix |21|----------|----------|--------|--------|22| 1 | Object Allocation | CRITICAL | `alloc-` |23| 2 | Collection & Enumeration | CRITICAL | `enum-` |24| 3 | I/O & Database | HIGH | `io-` |25| 4 | String Handling | HIGH | `str-` |26| 5 | Method & Dispatch | MEDIUM-HIGH | `meth-` |27| 6 | Data Structures | MEDIUM | `ds-` |28| 7 | Concurrency | MEDIUM | `conc-` |29| 8 | Runtime & Configuration | LOW-MEDIUM | `runtime-` |3031## Quick Reference3233### 1. Object Allocation (CRITICAL)3435- [`alloc-avoid-unnecessary-dup`](references/alloc-avoid-unnecessary-dup.md) - Avoid Unnecessary Object Duplication36- [`alloc-freeze-constants`](references/alloc-freeze-constants.md) - Freeze Constant Collections37- [`alloc-lazy-initialization`](references/alloc-lazy-initialization.md) - Use Lazy Initialization for Expensive Objects38- [`alloc-avoid-temp-arrays`](references/alloc-avoid-temp-arrays.md) - Avoid Temporary Array Creation39- [`alloc-reuse-buffers`](references/alloc-reuse-buffers.md) - Reuse Buffers in Loops40- [`alloc-avoid-implicit-conversions`](references/alloc-avoid-implicit-conversions.md) - Avoid Repeated Computation in Hot Paths4142### 2. Collection & Enumeration (CRITICAL)4344- [`enum-single-pass`](references/enum-single-pass.md) - Use Single-Pass Collection Transforms45- [`enum-lazy-large-collections`](references/enum-lazy-large-collections.md) - Use Lazy Enumerators for Large Collections46- [`enum-flat-map`](references/enum-flat-map.md) - Use flat_map Instead of map.flatten47- [`enum-each-with-object`](references/enum-each-with-object.md) - Use each_with_object Over inject for Building Collections48- [`enum-avoid-count-in-loops`](references/enum-avoid-count-in-loops.md) - Avoid Recomputing Collection Size in Conditions49- [`enum-chunk-batch-processing`](references/enum-chunk-batch-processing.md) - Use each_slice for Batch Processing5051### 3. I/O & Database (HIGH)5253- [`io-eager-load-associations`](references/io-eager-load-associations.md) - Eager Load ActiveRecord Associations54- [`io-select-only-needed-columns`](references/io-select-only-needed-columns.md) - Select Only Needed Columns55- [`io-batch-find-each`](references/io-batch-find-each.md) - Use find_each for Large Record Sets56- [`io-avoid-queries-in-loops`](references/io-avoid-queries-in-loops.md) - Avoid Database Queries Inside Loops57- [`io-stream-large-files`](references/io-stream-large-files.md) - Stream Large Files Line by Line58- [`io-connection-pool-sizing`](references/io-connection-pool-sizing.md) - Size Connection Pools to Match Thread Count59- [`io-cache-expensive-queries`](references/io-cache-expensive-queries.md) - Cache Expensive Database Results6061### 4. String Handling (HIGH)6263- [`str-frozen-literals`](references/str-frozen-literals.md) - Enable Frozen String Literals64- [`str-shovel-over-plus`](references/str-shovel-over-plus.md) - Use Shovel Operator for String Building65- [`str-interpolation-over-concatenation`](references/str-interpolation-over-concatenation.md) - Use String Interpolation Over Concatenation66- [`str-avoid-repeated-gsub`](references/str-avoid-repeated-gsub.md) - Chain gsub Calls into a Single Replacement67- [`str-symbol-for-identifiers`](references/str-symbol-for-identifiers.md) - Use Symbols for Identifiers and Hash Keys6869### 5. Method & Dispatch (MEDIUM-HIGH)7071- [`meth-avoid-method-missing-hot-paths`](references/meth-avoid-method-missing-hot-paths.md) - Avoid method_missing in Hot Paths72- [`meth-cache-method-references`](references/meth-cache-method-references.md) - Cache Method References for Repeated Calls73- [`meth-block-vs-proc`](references/meth-block-vs-proc.md) - Pass Blocks Directly Instead of Converting to Proc74- [`meth-avoid-dynamic-send`](references/meth-avoid-dynamic-send.md) - Avoid Dynamic send in Performance-Critical Code75- [`meth-reduce-method-chain-depth`](references/meth-reduce-method-chain-depth.md) - Reduce Method Chain Depth in Hot Loops7677### 6. Data Structures (MEDIUM)7879- [`ds-set-for-membership`](references/ds-set-for-membership.md) - Use Set for Membership Tests80- [`ds-struct-over-openstruct`](references/ds-struct-over-openstruct.md) - Use Struct Over OpenStruct81- [`ds-sort-by-over-sort`](references/ds-sort-by-over-sort.md) - Use sort_by Instead of sort with Block82- [`ds-array-preallocation`](references/ds-array-preallocation.md) - Preallocate Arrays When Size Is Known83- [`ds-hash-default-value`](references/ds-hash-default-value.md) - Use Hash Default Values Instead of Conditional Assignment8485### 7. Concurrency (MEDIUM)8687- [`conc-fiber-for-io`](references/conc-fiber-for-io.md) - Use Fibers for I/O-Bound Concurrency88- [`conc-thread-pool-sizing`](references/conc-thread-pool-sizing.md) - Size Thread Pools to Match Workload89- [`conc-ractor-cpu-bound`](references/conc-ractor-cpu-bound.md) - Use Ractors for CPU-Bound Parallelism90- [`conc-avoid-shared-mutable-state`](references/conc-avoid-shared-mutable-state.md) - Avoid Shared Mutable State Between Threads9192### 8. Runtime & Configuration (LOW-MEDIUM)9394- [`runtime-enable-yjit`](references/runtime-enable-yjit.md) - Enable YJIT for Production95- [`runtime-tune-gc-parameters`](references/runtime-tune-gc-parameters.md) - Tune GC Parameters for Your Workload96- [`runtime-frozen-string-literal-default`](references/runtime-frozen-string-literal-default.md) - Set Frozen String Literal as Project Default97- [`runtime-optimize-require`](references/runtime-optimize-require.md) - Optimize Require Load Order9899## How to Use100101Read individual reference files for detailed explanations and code examples:102103- [Section definitions](references/_sections.md) - Category structure and impact levels104- [Rule template](assets/templates/_template.md) - Template for adding new rules105106## Reference Files107108| File | Description |109|------|-------------|110| [references/_sections.md](references/_sections.md) | Category definitions and ordering |111| [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules |112| [metadata.json](metadata.json) | Version and reference information |
Run npx skillmds@latest add comeonoliver/ruby-optimise in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Community Ruby Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.