NI

Nim Performance

Performance optimization in Nim using memory management strategies, compilation flags, and profiling

Details

Language / Topic
nimNim
Category
Performance

Rules

balanced
- Compile with `--opt:speed` for release builds and `--opt:size` for embedded or CLI tools — never ship debug builds (`--opt:none`) to production.
- Use `--mm:arc` or `--mm:orc` (the ownership-based memory managers) instead of the default GC for predictable, low-latency memory reclamation without stop-the-world pauses.
- Avoid unnecessary `string` copies — use `openArray[char]` or `cstring` for read-only string parameters and `sink` parameters to transfer ownership without copying.
- Use `{.inline.}` pragma on hot small procedures to hint the C backend to inline them — verify impact with `--listCmd` to inspect the generated C output.