ER

Erlang Performance

Erlang performance patterns for efficient message passing, binary handling, and process scheduling

Details

Language / Topic
erlangErlang
Category
Performance

Rules

balanced
- Use binaries (`<<Data/binary>>`) for large data passing between processes — binaries larger than 64 bytes are stored on a shared heap and not copied.
- Avoid sending large data structures in messages — prefer ETS or persistent storage references and pass keys/identifiers instead.
- Use `ets:lookup/2` for O(1) concurrent reads across multiple processes — prefer `ordered_set` for range scans and `set` for point lookups.
- Profile with `fprof` or `eprof` to identify CPU hotspots — use `fprof:apply(Fun, Args)` and analyse the output with `fprof:analyse`.
- Use `binary:match/2` and `binary:split/3` for binary pattern matching — they are faster than building equivalent recursive clause patterns.
- Avoid recursive list building without `lists:reverse/1` — always build lists by prepending and reverse at the end for O(n) construction.
- Use `erlang:system_monitor/2` with `{long_gc, Milliseconds}` to detect GC pauses in long-lived processes that process large heaps.