ruby-optimise
Community Ruby Best Practices
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
- Reviewing code for memory bloat and GC pressure
- Configuring Ruby runtime settings for production
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Object Allocation | CRITICAL | alloc- |
| 2 | Collection & Enumeration | CRITICAL | enum- |
| 3 | I/O & Database | HIGH | io- |
| 4 | String Handling | HIGH | str- |
| 5 | Method & Dispatch | MEDIUM-HIGH | meth- |
| 6 | Data Structures | MEDIUM | ds- |
| 7 | Concurrency | MEDIUM | conc- |
| 8 | Runtime & Configuration | LOW-MEDIUM | runtime- |
Quick Reference
1. Object Allocation (CRITICAL)
alloc-avoid-unnecessary-dup- Avoid Unnecessary Object Duplicationalloc-freeze-constants- Freeze Constant Collectionsalloc-lazy-initialization- Use Lazy Initialization for Expensive Objectsalloc-avoid-temp-arrays- Avoid Temporary Array Creationalloc-reuse-buffers- Reuse Buffers in Loopsalloc-avoid-implicit-conversions- Avoid Repeated Computation in Hot Paths
2. Collection & Enumeration (CRITICAL)
enum-single-pass- Use Single-Pass Collection Transformsenum-lazy-large-collections- Use Lazy Enumerators for Large Collectionsenum-flat-map- Use flat_map Instead of map.flattenenum-each-with-object- Use each_with_object Over inject for Building Collectionsenum-avoid-count-in-loops- Avoid Recomputing Collection Size in Conditionsenum-chunk-batch-processing- Use each_slice for Batch Processing
3. I/O & Database (HIGH)
io-eager-load-associations- Eager Load ActiveRecord Associationsio-select-only-needed-columns- Select Only Needed Columnsio-batch-find-each- Use find_each for Large Record Setsio-avoid-queries-in-loops- Avoid Database Queries Inside Loopsio-stream-large-files- Stream Large Files Line by Lineio-connection-pool-sizing- Size Connection Pools to Match Thread Countio-cache-expensive-queries- Cache Expensive Database Results
4. String Handling (HIGH)
str-frozen-literals- Enable Frozen String Literalsstr-shovel-over-plus- Use Shovel Operator for String Buildingstr-interpolation-over-concatenation- Use String Interpolation Over Concatenationstr-avoid-repeated-gsub- Chain gsub Calls into a Single Replacementstr-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 Pathsmeth-cache-method-references- Cache Method References for Repeated Callsmeth-block-vs-proc- Pass Blocks Directly Instead of Converting to Procmeth-avoid-dynamic-send- Avoid Dynamic send in Performance-Critical Codemeth-reduce-method-chain-depth- Reduce Method Chain Depth in Hot Loops
6. Data Structures (MEDIUM)
ds-set-for-membership- Use Set for Membership Testsds-struct-over-openstruct- Use Struct Over OpenStructds-sort-by-over-sort- Use sort_by Instead of sort with Blockds-array-preallocation- Preallocate Arrays When Size Is Knownds-hash-default-value- Use Hash Default Values Instead of Conditional Assignment
7. Concurrency (MEDIUM)
conc-fiber-for-io- Use Fibers for I/O-Bound Concurrencyconc-thread-pool-sizing- Size Thread Pools to Match Workloadconc-ractor-cpu-bound- Use Ractors for CPU-Bound Parallelismconc-avoid-shared-mutable-state- Avoid Shared Mutable State Between Threads
8. Runtime & Configuration (LOW-MEDIUM)
runtime-enable-yjit- Enable YJIT for Productionruntime-tune-gc-parameters- Tune GC Parameters for Your Workloadruntime-frozen-string-literal-default- Set Frozen String Literal as Project Defaultruntime-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 |
More from pproenca/dot-skills
zod
Zod schema validation best practices for type safety, parsing, and error handling. This skill should be used when defining z.object schemas, using z.string validations, safeParse, or z.infer. This skill does NOT cover React Hook Form integration patterns (use react-hook-form skill) or OpenAPI client generation (use orval skill).
2.0Kclean-architecture
Clean Architecture principles and best practices from Robert C. Martin's book. This skill should be used when designing software systems, reviewing code structure, or refactoring applications to achieve better separation of concerns. Triggers on tasks involving layers, boundaries, dependency direction, entities, use cases, or system architecture.
1.4Kemilkowal-animations
Emil Kowalski's animation best practices for web interfaces. Use when writing, reviewing, or implementing animations in React, CSS, or Framer Motion. Triggers on tasks involving transitions, easing, gestures, toasts, drawers, or motion.
917vitest
Vitest testing framework patterns for test setup, async testing, mocking with vi.*, snapshots, and test performance (formerly test-vitest). This skill should be used when writing or debugging Vitest tests. This skill does NOT cover TDD methodology (use test-tdd skill), API mocking with MSW (use test-msw skill), or Jest-specific APIs.
906typescript
This skill should be used when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.
820nuqs
nuqs (type-safe URL query state) best practices for Next.js applications. This skill should be used when writing, reviewing, or refactoring code that uses nuqs for URL state management. Triggers on tasks involving useQueryState, useQueryStates, search params, URL state, query parameters, nuqs parsers, or Next.js routing with state.
734