FFORGE//RS
← Roadmap

rust / LEVEL 4

The flamegraph made of tiny allocations

EST.40 MIN
01

THEORY / RETRIEVAL

What to restore

  • Translate an allocation profile into a targeted code change
  • Pre-size a String and append borrowed slices directly

Profile before optimizing

A hot allocator frame often points to repeated temporary ownership rather than expensive business logic. Confirm the call path and workload first; then remove allocations at the narrowest responsible layer.

Capacity is a performance contract, not correctness

`String::with_capacity` can avoid growth reallocations when the final byte size is cheap to compute. It must not change separators, Unicode bytes or empty-input behavior, and an allocation test should tolerate implementation details outside the measured region.

CHECKPOINT

A profile attributes most time to allocating temporary Strings inside a join loop. What is the most targeted first change?

ISOLATED RUST 1.96
src/lib.rsEDIT

02 / PROFILING

Read the profile and fix the cause

Rewrite `join_tags` to produce identical comma-separated output with at most one allocation for non-empty input. Do not use `join`, `format!`, or per-tag owned Strings.

Initializing editor…
CLOUD SANDBOXnetwork off · 256 MB · 12 s
1 / 64 KB
OUTPUT
Runner is waiting for a submission.