elixir-performance-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Elixir Performance Review

Elixir性能审查

Quick Reference

快速参考

Issue TypeReference
Mailbox overflow, blocking callsreferences/genserver-bottlenecks.md
When to use ETS, read/write concurrencyreferences/ets-patterns.md
Binary handling, large messagesreferences/memory.md
Task patterns, flow controlreferences/concurrency.md
问题类型参考链接
邮箱溢出、阻塞调用references/genserver-bottlenecks.md
ETS的使用场景、读写并发references/ets-patterns.md
二进制数据处理、大型消息references/memory.md
Task模式、流控制references/concurrency.md

Review Checklist

审查清单

GenServer

GenServer

  • Not a single-process bottleneck for all requests
  • No blocking operations in handle_call/cast
  • Proper timeout configuration
  • Consider ETS for read-heavy state
  • 并非所有请求都依赖单进程(无单进程瓶颈)
  • handle_call/cast中无阻塞操作
  • 正确配置超时时间
  • 针对读密集型状态考虑使用ETS

Memory

内存

  • Large binaries not copied between processes
  • Streams used for large data transformations
  • No unbounded data accumulation
  • 进程间不复制大型二进制数据
  • 使用Streams处理大型数据转换
  • 无无限制的数据累积

Concurrency

并发

  • Task.Supervisor for dynamic tasks (not raw Task.async)
  • No unbounded process spawning
  • Proper backpressure for message producers
  • 使用Task.Supervisor管理动态任务(而非直接使用Task.async)
  • 无无限制的进程生成
  • 为消息生产者设置适当的背压

Database

数据库

  • Preloading to avoid N+1 queries
  • Pagination for large result sets
  • Indexes for frequent queries
  • 使用预加载避免N+1查询
  • 对大型结果集使用分页
  • 为频繁查询创建索引

Valid Patterns (Do NOT Flag)

有效模式(无需标记)

  • Single GenServer for low-throughput - Not all state needs horizontal scaling
  • Synchronous calls for critical paths - Consistency may require it
  • In-memory state without ETS - ETS has overhead for small state
  • Enum over Stream for small collections - Stream overhead not worth it
  • 低吞吐量场景下使用单GenServer - 并非所有状态都需要水平扩展
  • 关键路径使用同步调用 - 一致性需求可能需要这么做
  • 不使用ETS的内存状态 - 小型状态使用ETS会有额外开销
  • 小型集合使用Enum而非Stream - Stream的额外开销得不偿失

Context-Sensitive Rules

上下文敏感规则

IssueFlag ONLY IF
GenServer bottleneckHandles > 1000 req/sec OR blocking I/O in callbacks
Use streamsProcessing > 10k items OR reading large files
Use ETSRead:write ratio > 10:1 AND concurrent access
问题仅在以下情况标记
GenServer瓶颈处理请求>1000次/秒 或 回调中存在阻塞I/O
使用Streams处理>10000条数据 或 读取大文件
使用ETS读/写比>10:1 且 存在并发访问

Before Submitting Findings

提交检查结果前

Load and follow review-verification-protocol before reporting any issue.
在报告任何问题前,请加载并遵循审查验证协议